Skip to content

Commit

Permalink
Add other libs (niklasb#25)
Browse files Browse the repository at this point in the history
* Adapt API to other libc + Add Musl

* Adapt regex to extract symbols (thank's @blukat29)

Regex from @blukat29 (blukat29@287ca62#diff-6f1488814a51063192c9aabb59112ef1R11)

* Add Alpine

* Add DietLibc

* Fix symbols extracting regex
  • Loading branch information
ajabep authored Oct 19, 2020
1 parent 92d5c36 commit 4c77106
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 26 deletions.
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ In addition of RPM-Based requirements, you will need:
* tar


### APK Based

* mktemp
* perl
* wget
* tar
* gzip
* grep


### Install everything

To install everything on Debian 10, run these commands:
Expand Down
91 changes: 79 additions & 12 deletions common/libc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ die() {
}

dump_symbols() {
readelf -Ws $1 | perl -n -e '/: (\w*).*?(\w+)@@GLIBC_/ && print "$2 $1\n"'
readelf -Ws $1 | perl -n -e '/: (\w+)\s+\w+\s+(?:FUNC|OBJECT)\s+(?:\w+\s+){3}(\w+)\b(?:@@GLIBC)?/ && print "$2 $1\n"' | sort -u
}

extract_label() {
Expand Down Expand Up @@ -96,10 +96,11 @@ requirements_general() {
get_debian() {
local url="$1"
local info="$2"
local pkgname="$3"
local tmp=`mktemp -d`
echo "Getting $info"
echo " -> Location: $url"
local id=`echo $url | perl -n -e '/(libc6[^\/]*)\./ && print $1'`
local id=`echo $url | perl -n -e '/('"$pkgname"'[^\/]*)\./ && print $1'`
echo " -> ID: $id"
check_id $id || return
echo " -> Downloading package"
Expand All @@ -116,8 +117,9 @@ get_debian() {
get_all_debian() {
local info=$1
local url=$2
for f in `wget $url/ -O - 2>/dev/null | grep -Eoh 'libc6(-i386|-amd64)?_[^"]*(amd64|i386)\.deb' |grep -v "</a>"`; do
get_debian $url/$f $1
local pkgname=$3
for f in `wget $url/ -O - 2>/dev/null | grep -Eoh "$pkgname"'(-i386|-amd64|-x32)?_[^"]*(amd64|i386)\.deb' |grep -v "</a>"`; do
get_debian "$url/$f" "$info" "$pkgname"
done
return 0
}
Expand All @@ -137,10 +139,11 @@ requirements_debian() {
get_rpm() {
local url="$1"
local info="$2"
local pkgname="$3"
local tmp="$(mktemp -d)"
echo "Getting $info"
echo " -> Location: $url"
local id=$(echo "$url" | perl -n -e '/(libc[^\/]*)\./ && print $1')
local id=$(echo "$url" | perl -n -e '/('"$pkgname"'[^\/]*)\./ && print $1')
echo " -> ID: $id"
check_id "$id" || return
echo " -> Downloading package"
Expand All @@ -157,22 +160,23 @@ get_rpm() {
get_all_rpm() {
local info=$1
local pkg=$2
local arch=$3
local pkgname=$3
local arch=$4
local website="http://rpmfind.net"
local searchurl="$website/linux/rpm2html/search.php?query=$pkg"
echo "Getting package $pkg locations"
local url=""
for i in $(seq 1 3); do
urls=$(wget "$searchurl" -O - 2>/dev/null \
| grep -oh "/[^']*libc[^']*\.$arch\.rpm")
| grep -oh "/[^']*${pkgname}[^']*\.$arch\.rpm")
[[ -z "$urls" ]] || break
echo "Retrying..."
sleep 1
done
[[ -n "$urls" ]] || die "Failed to get package version"
for url in $urls
do
get_rpm "$website$url" "$info"
get_rpm "$website$url" "$info" "$pkgname"
sleep .1
done
}
Expand Down Expand Up @@ -208,7 +212,7 @@ get_from_filelistgz() {
[[ -n "$urls" ]] || die "Failed to get package version"
for url in $urls
do
get_rpm "$website/$url" "$info"
get_rpm "$website/$url" "$info" "$pkg"
sleep .1
done
}
Expand All @@ -227,10 +231,11 @@ requirements_centos() {
get_pkg() {
local url="$1"
local info="$2"
local pkgname="$3"
local tmp="$(mktemp -d)"
echo "Getting $info"
echo " -> Location: $url"
local id=$(echo "$url" | perl -n -e '/(libc[^\/]*)\.pkg\.tar\.(xz|zst)/ && print $1' | ( (echo "$url" | grep -q 'lib32') && sed 's/x86_64/x86/g' || cat))
local id=$(echo "$url" | perl -n -e '/('"$pkgname"'[^\/]*)\.pkg\.tar\.(xz|zst)/ && print $1' | ( (echo "$url" | grep -q 'lib32') && sed 's/x86_64/x86/g' || cat))
echo " -> ID: $id"
check_id $id || return
echo " -> Downloading package"
Expand All @@ -256,11 +261,12 @@ get_pkg() {
get_all_pkg() {
local info=$1
local directory=$2
local pkgname=$3
echo "Getting package $info locations"
local url=""
for i in $(seq 1 3); do
urls=$(wget "$directory" -O - 2>/dev/null \
| grep -oh '[^"]*libc[^"]*\.pkg[^"]*' \
| grep -oh '[^"]*'"$pkgname"'[^"]*\.pkg[^"]*' \
| grep -v '.sig' \
| grep -v '>')
[[ -z "$urls" ]] || break
Expand All @@ -270,7 +276,7 @@ get_all_pkg() {
[[ -n "$urls" ]] || die "Failed to get package version"
for url in $urls
do
get_pkg "$directory/$url" "$info"
get_pkg "$directory/$url" "$info" "$pkgname"
sleep .1
done
}
Expand All @@ -288,6 +294,67 @@ requirements_pkg() {
return 0
}


# ===== Alpine ===== #

get_apk() {
local url="$1"
local info="$2"229
local pkgname="$3"
local tmp=$(mktemp -d)
echo "Getting $info"
echo " -> Location: $url"
local id=$(echo "$url" | perl -n -e '/('"$pkgname"'[^\/]*)\.apk/ && print $1')
echo " -> ID: $id"
check_id $id || return
echo " -> Downloading package"
wget "$url" 2>/dev/null -O "$tmp/pkg.tar.gz" || die "Failed to download package from $url"
echo " -> Extracting package"
pushd $tmp 1>/dev/null
tar xzf pkg.tar.gz --warning=none
popd 1>/dev/null
index_libc "$tmp" "$id" "$info" "$url"
rm -rf $tmp
}

get_all_apk() {
local info=$1
local repo=$2
local version=$3
local component=$4
local arch=$5
local pkgname=$6
local directory="$repo/$version/$component/$arch/"
echo "Getting package $info locations"
local url=""
for i in $(seq 1 3); do
urls=$(wget "$directory" -O - 2>/dev/null \
| grep -oh '[^"]*'"$pkgname"'-[0-9][^"]*\.apk' \
| grep -v '.sig' \
| grep -v '>')
[[ -z "$urls" ]] || break
echo "Retrying..."
sleep 1
done
[[ -n "$urls" ]] || die "Failed to get package version"
for url in $urls
do
get_apk "$directory$url" "$info" "$pkgname"
sleep .1
done
}

requirements_apk() {
which mktemp 1>/dev/null 2>&1 || return
which perl 1>/dev/null 2>&1 || return
which wget 1>/dev/null 2>&1 || return
which tar 1>/dev/null 2>&1 || return
which gzip 1>/dev/null 2>&1 || return
which grep 1>/dev/null 2>&1 || return
return 0
}


# ===== Local ===== #

add_local() {
Expand Down
70 changes: 56 additions & 14 deletions get
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,39 @@ categories[cntr_category]="ubuntu"
requirements["ubuntu"]="requirements_debian"
cntr_category=$((cntr_category + 1))
ubuntu() {
get_all_debian ubuntu-eglibc http://archive.ubuntu.com/ubuntu/pool/main/e/eglibc/
get_all_debian ubuntu-glibc http://archive.ubuntu.com/ubuntu/pool/main/g/glibc/
get_all_debian ubuntu-security-eglibc http://security.ubuntu.com/ubuntu/pool/main/e/eglibc/
get_all_debian ubuntu-security-glibc http://security.ubuntu.com/ubuntu/pool/main/g/glibc/
get_all_debian ubuntu-old-eglibc http://old-releases.ubuntu.com/ubuntu/pool/main/e/eglibc/
get_all_debian ubuntu-old-glibc http://old-releases.ubuntu.com/ubuntu/pool/main/g/glibc/
get_all_debian ubuntu-eglibc http://archive.ubuntu.com/ubuntu/pool/main/e/eglibc/ libc6
get_all_debian ubuntu-glibc http://archive.ubuntu.com/ubuntu/pool/main/g/glibc/ libc6
get_all_debian ubuntu-musl http://archive.ubuntu.com/ubuntu/pool/universe/m/musl/ musl
get_all_debian ubuntu-dietlibc http://archive.ubuntu.com/ubuntu/pool/universe/d/dietlibc/ dietlibc
get_all_debian ubuntu-security-eglibc http://security.ubuntu.com/ubuntu/pool/main/e/eglibc/ libc6
get_all_debian ubuntu-security-glibc http://security.ubuntu.com/ubuntu/pool/main/g/glibc/ libc6
get_all_debian ubuntu-security-musl http://security.ubuntu.com/ubuntu/pool/universe/m/musl/ musl
get_all_debian ubuntu-security-dietlibc http://security.ubuntu.com/ubuntu/pool/universe/d/dietlibc/ dietlibc
get_all_debian ubuntu-old-eglibc http://old-releases.ubuntu.com/ubuntu/pool/main/e/eglibc/ libc6
get_all_debian ubuntu-old-glibc http://old-releases.ubuntu.com/ubuntu/pool/main/g/glibc/ libc6
get_all_debian ubuntu-old-musl http://old-releases.ubuntu.com/ubuntu/pool/universe/m/musl/ musl
get_all_debian ubuntu-old-dietlibc http://old-releases.ubuntu.com/ubuntu/pool/universe/d/dietlibc/ dietlibc
}

categories[cntr_category]="debian"
requirements["debian"]="requirements_debian"
cntr_category=$((cntr_category + 1))
debian() {
get_all_debian debian-glibc https://deb.debian.org/debian/pool/main/g/glibc
get_all_debian debian-glibc https://deb.debian.org/debian/pool/main/g/glibc/ libc6
get_all_debian debian-musl https://deb.debian.org/debian/pool/main/m/musl/ musl
get_all_debian debian-dietlibc https://deb.debian.org/debian/pool/main/d/dietlibc/ dietlibc
}

categories[cntr_category]="rpm"
requirements["rpm"]="requirements_rpm"
cntr_category=$((cntr_category + 1))
rpm() {
get_all_rpm rpm glibc x86_64
get_all_rpm rpm glibc i586
get_all_rpm rpm glibc i686
get_all_rpm rpm glibc libc x86_64
get_all_rpm rpm glibc libc i586
get_all_rpm rpm glibc libc i686
get_all_rpm rpm musl musl x86_64
get_all_rpm rpm musl musl i586
get_all_rpm rpm musl musl i686
}

categories[cntr_category]="centos"
Expand All @@ -46,21 +57,52 @@ categories[cntr_category]="arch"
requirements["arch"]="requirements_pkg"
cntr_category=$((cntr_category + 1))
arch() {
get_all_pkg arch-glibc https://archive.archlinux.org/packages/g/glibc/
get_all_pkg arch-lib32-glibc https://archive.archlinux.org/packages/l/lib32-glibc/
get_all_pkg arch-glibc https://archive.archlinux.org/packages/g/glibc/ libc
get_all_pkg arch-lib32-glibc https://archive.archlinux.org/packages/l/lib32-glibc/ libc
get_all_pkg arch-musl https://archive.archlinux.org/packages/m/musl/ musl
}

categories[cntr_category]="alpine"
requirements["alpine"]="requirements_apk"
cntr_category=$((cntr_category + 1))
alpine() {
alpine_versions=(
latest-stable
edge
v3.0
v3.1
v3.2
v3.3
v3.4
v3.5
v3.6
v3.7
v3.8
v3.9
v3.10
v3.11
v3.12
)

for version in "${alpine_versions[@]}"; do
get_all_apk alpine-musl http://dl-cdn.alpinelinux.org/alpine/ "$version" main x86_64 musl
get_all_apk alpine-musl http://dl-cdn.alpinelinux.org/alpine/ "$version" main x86 musl
done
}

categories[cntr_category]="kali"
requirements["kali"]="requirements_debian"
cntr_category=$((cntr_category + 1))
kali() {
get_all_debian kali-glibc https://http.kali.org/pool/main/g/glibc/
get_all_debian kali-glibc https://http.kali.org/pool/main/g/glibc/ libc6
get_all_debian kali-musl https://http.kali.org/pool/main/m/musl/ musl
}
categories[cntr_category]="parrotsec"
requirements["parrotsec"]="requirements_debian"
cntr_category=$((cntr_category + 1))
parrotsec() {
get_all_debian parrotsec-glibc https://download.parrot.sh/parrot/pool/main/g/glibc/
get_all_debian parrotsec-glibc https://download.parrot.sh/parrot/pool/main/g/glibc/ libc6
get_all_debian parrotsec-musl https://download.parrot.sh/parrot/pool/main/m/musl/ musl
}


Expand Down

0 comments on commit 4c77106

Please sign in to comment.