Use dockerized build. Add KCP. TBD: android

This commit is contained in:
Oleksii Shevchuk 2018-01-04 23:45:40 +02:00
parent ea3f247a28
commit 131c9629f0
4 changed files with 267 additions and 1 deletions

11
client/docker-build.sh Executable file
View File

@ -0,0 +1,11 @@
#!/bin/sh
SELF=`readlink -f "$0"`
PUPY=`dirname "$SELF"`/../
PUPY=`readlink -f "$PUPY"`
echo $PUPY
docker run -v $PUPY:/build/workspace/project alxchk/tc-windows client/sources/build-docker.sh
docker run -v $PUPY:/build/workspace/project alxchk/tc-linux32 client/sources-linux/build-docker.sh
docker run -v $PUPY:/build/workspace/project alxchk/tc-linux64 client/sources-linux/build-docker.sh

View File

@ -0,0 +1,118 @@
#!/bin/sh
SELF=`readlink -f "$0"`
SELFPWD=`dirname "$SELF"`
SRC=${SELFPWD:-`pwd`}
cd $SRC
TEMPLATES=`readlink -f ../../pupy/payload_templates`
PYKCP=../../pupy/external/pykcp
set -e
echo "[+] Install python packages"
python -OO -m pip install --upgrade setuptools
python -OO -m pip install pycparser==2.17
python -OO -m pip install -q six packaging appdirs
CC=/gccwrap CFLAGS_ABORT="-D_FORTIFY_SOURCE=2 -fstack-protector" \
python -OO -m pip install -q pynacl --no-binary :all:
CC=/gccwrap CFLAGS_FILTER="-Wno-error=sign-conversion" \
python -OO -m pip install -q cryptography --no-binary :all:
python -OO -m pip install \
rpyc pycryptodome pyaml rsa netaddr tinyec pyyaml ecdsa \
paramiko pylzma pydbus python-ptrace psutil scandir \
scapy impacket colorama pyOpenSSL \
--no-binary :all:
echo "[+] Compile pykcp"
python -OO -m pip install $PYKCP
echo "[+] Compile pyuv"
if [ "$TOOLCHAIN_ARCH" == "x86" ]; then
CFLAGS_PYUV="-O2 -pipe -DCLOCK_MONOTONIC=1 -UHAVE_PTHREAD_COND_TIMEDWAIT_MONOTONIC"
CFLAGS_PYUV="$CFLAGS_PYUV -U_FILE_OFFSET_BITS -D_XOPEN_SOURCE=600 "
CFLAGS_PYUV="$CFLAGS_PYUV -D_GNU_SOURCE -DS_ISSOCK(m)='(((m) & S_IFMT) == S_IFSOCK)'"
CC=/gccwrap CFLAGS_FILTER="-D_FILE_OFFSET_BITS=64" CFLAGS="$CFLAGS_PYUV" \
python -OO -m pip install pyuv --no-binary :all:
else
CFLAGS="$CFLAGS -D_XOPEN_SOURCE=600 -D_GNU_SOURCE -DS_ISSOCK(m)='(((m) & S_IFMT) == S_IFSOCK)'" \
python -OO -m pip install pyuv --no-binary :all:
fi
echo "[+] Compile python files"
cd /usr/lib/python2.7
find -name "*.py" | python -m compileall -qfi -
find -name "*.py" | python -OO -m compileall -qfi -
echo "[+] Strip python modules"
find -name "*.so" | while read f; do strip $f; done
echo "[+] Build python template ($TOOLCHAIN_ARCH)"
rm -f ${TEMPLATES}/linux-${TOOLCHAIN_ARCH}.zip
zip -y -r -9 ${TEMPLATES}/linux-${TOOLCHAIN_ARCH}.zip . \
-x "*.a" -x "*.la" -x "*.o" -x "*.whl" -x "*.txt" -x "*.py" -x "*.pyc" \
-x "*test/*" -x "*tests/*" -x "*examples/*" \
-x "*.egg-info/*" -x "*.dist-info/*" \
-x "idlelib/*" -x "lib-tk/*" -x "tk*" -x "tcl*" >/dev/null
ldconfig
echo "[+] Build pupy"
case $TOOLCHAIN_ARCH in
amd64)
MAKEFLAGS="ARCH=64 PIE="
TARGETS="pupyx64d.lin pupyx64d.lin.so pupyx64d.unc.lin"
TARGETS="$TARGETS pupyx64d.unc.lin.so pupyx64.lin pupyx64.lin.so"
TARGETS="$TARGETS pupyx64.unc.lin pupyx64.unc.lin.so"
;;
x86)
MAKEFLAGS="ARCH=32 PIE="
TARGETS="pupyx86d.lin pupyx86d.lin.so"
TARGTS="$TARGETS pupyx86d.unc.lin pupyx86d.unc.lin.so pupyx86.lin pupyx86.lin.so"
TARGETS="$TARGETS pupyx86.unc.lin pupyx86.unc.lin.so"
;;
esac
for target in $TARGETS; do rm -f $TEMPLATES/$target; done
cd $SRC
make clean
make -j $MAKEFLAGS
make clean
make -j DEBUG=1 $MAKEFLAGS
make clean
make -j UNCOMPRESSED=1 $MAKEFLAGS
make clean
make -j DEBUG=1 UNCOMPRESSED=1 $MAKEFLAGS
make distclean
for object in $TARGETS; do
if [ -z "$object" ]; then
continue
fi
if [ ! -f $TEMPLATES/$object ]; then
echo "[-] $object - failed"
FAILED=1
fi
done
if [ -z "$FAILED" ]; then
echo "[+] Build complete"
else
echo "[-] Build failed"
exit 1
fi

137
client/sources/build-docker.sh Executable file
View File

@ -0,0 +1,137 @@
#!/bin/sh
PACKAGES="rpyc rsa pefile rsa netaddr win_inet_pton netaddr tinyec pypiwin32"
PACKAGES_BUILD="pycryptodome cryptography netifaces"
PACKAGES="$PACKAGES pyaudio https://github.com/secdev/scapy/archive/master.zip pyOpenSSL colorama pyuv"
PACKAGES="$PACKAGES https://github.com/CoreSecurity/impacket/archive/master.zip"
SELF=`readlink -f "$0"`
SELFPWD=`dirname "$SELF"`
SRC=${SELFPWD:-`pwd`}
cd $SRC
WINPTY=../../pupy/external/winpty
PYKCP=../../pupy/external/pykcp
echo "[+] Install python packages"
for PYTHON in $PYTHON32 $PYTHON64; do
$PYTHON -OO -m pip install -q --upgrade pip
$PYTHON -OO -m pip install -q --upgrade setuptools
$PYTHON -OO -m pip install -q pycparser==2.17
$PYTHON -OO -m pip install $PACKAGES
$PYTHON -OO -m pip install --no-binary :all: $PACKAGES_BUILD
$PYTHON -OO -m pip install --upgrade --force $PYKCP
done
echo "[+] Install psutil"
$PYTHON32 -OO -m pip install --no-binary :all: psutil==4.3.1
$PYTHON64 -OO -m pip install --no-binary :all: psutil
echo "[+] Compile python files"
for PYTHON in $PYTHON32 $PYTHON64; do
$PYTHON -m compileall -q C:\\Python27\\Lib >/dev/null || true
$PYTHON -OO -m compileall -q C:\\Python27\\Lib >/dev/null || true
done
echo "[+] Compile pupymemexec /32"
$CL32 \
../../pupy/packages/src/pupymemexec/pupymemexec.c \
/LD /D_WIN32 /IC:\\Python27\\Include \
C:\\Python27\\libs\\python27.lib advapi32.lib \
/FeC:\\Python27\\Lib\\site-packages\\pupymemexec.pyd
echo "[+] Compile pupymemexec /64"
$CL64 \
../../pupy/packages/src/pupymemexec/pupymemexec.c \
/LD /D_WIN64 /IC:\\Python27\\Include \
C:\\Python27\\libs\\python27.lib advapi32.lib \
/FeC:\\Python27\\Lib\\site-packages\\pupymemexec.pyd
echo "[+] Compile winpty /32"
make -C ${WINPTY} clean
make -C ${WINPTY} MINGW_CXX="${MINGW32} -Os -s" build/winpty.dll
mv $WINPTY/build/winpty.dll ${WINE32}/drive_c/Python27/DLLs/
echo "[+] Compile winpty /64"
make -C ${WINPTY} clean
make -C ${WINPTY} MINGW_CXX="${MINGW64} -Os -s" build/winpty.dll
mv ${WINPTY}/build/winpty.dll ${WINE64}/drive_c/Python27/DLLs/
TEMPLATES=`readlink -f ../../pupy/payload_templates`
echo "[+] Build templates /32"
cd $WINE32/drive_c/Python27
rm -f ${TEMPLATES}/windows-x86.zip
for dir in Lib DLLs; do
cd $dir
zip -q -y \
-x "*.a" -x "*.o" -x "*.whl" -x "*.txt" -x "*.py" -x "*.pyc" -x "*.chm" \
-x "*test/*" -x "*tests/*" -x "*examples/*" -x "pythonwin/*" \
-x "idlelib/*" -x "lib-tk/*" -x "tk*" -x "tcl*" \
-x "*.egg-info/*" -x "*.dist-info/*" -x "*.exe" \
-r9 ${TEMPLATES}/windows-x86.zip .
cd -
done
cd $WINE64/drive_c/Python27
rm -f ${TEMPLATES}/windows-amd64.zip
echo "[+] Build templates /64"
for dir in Lib DLLs; do
cd $dir
zip -q -y \
-x "*.a" -x "*.o" -x "*.whl" -x "*.txt" -x "*.py" -x "*.pyc" -x "*.chm" \
-x "*test/*" -x "*tests/*" -x "*examples/*" -x "pythonwin/*" \
-x "idlelib/*" -x "lib-tk/*" -x "tk*" -x "tcl*" \
-x "*.egg-info/*" -x "*.dist-info/*" -x "*.exe" \
-r9 ${TEMPLATES}/windows-amd64.zip .
cd -
done
echo "[+] Build pupy"
TARGETS="pupyx64d.dll pupyx64d.exe pupyx64.dll pupyx64d.unc.dll pupyx64d.unc.exe"
TARGETS="$TARGETS pupyx64.exe pupyx64.unc.dll pupyx64.unc.exe pupyx86d.dll pupyx86d.exe pupyx86.dll"
TARGETS="$TARGETS pupyx86d.unc.dll pupyx86d.unc.exe pupyx86.exe pupyx86.unc.dll pupyx86.unc.exe"
cd ${SRC}
for target in $TARGETS; do rm -f $TEMPLATES/$target; done
make -f Makefile -j BUILDENV=/build ARCH=win32 clean
make -f Makefile -j BUILDENV=/build ARCH=win32
make -f Makefile -j BUILDENV=/build DEBUG=1 ARCH=win32 clean
make -f Makefile -j BUILDENV=/build DEBUG=1 ARCH=win32
make -f Makefile -j BUILDENV=/build ARCH=win32 UNCOMPRESSED=1 clean
make -f Makefile -j BUILDENV=/build ARCH=win32 UNCOMPRESSED=1
make -f Makefile -j BUILDENV=/build DEBUG=1 ARCH=win32 UNCOMPRESSED=1 clean
make -f Makefile -j BUILDENV=/build DEBUG=1 ARCH=win32 UNCOMPRESSED=1
make -f Makefile -j BUILDENV=/build ARCH=win64 distclean
make -f Makefile -j BUILDENV=/build ARCH=win64
make -f Makefile -j BUILDENV=/build DEBUG=1 ARCH=win64 clean
make -f Makefile -j BUILDENV=/build DEBUG=1 ARCH=win64
make -f Makefile -j BUILDENV=/build ARCH=win64 UNCOMPRESSED=1 clean
make -f Makefile -j BUILDENV=/build ARCH=win64 UNCOMPRESSED=1
make -f Makefile -j BUILDENV=/build DEBUG=1 ARCH=win64 UNCOMPRESSED=1 clean
make -f Makefile -j BUILDENV=/build DEBUG=1 ARCH=win64 UNCOMPRESSED=1
make -f Makefile -j BUILDENV=/build ARCH=win64 UNCOMPRESSED=1 distclean
for object in $TARGETS; do
if [ -z "$object" ]; then
continue
fi
if [ ! -f $TEMPLATES/$object ]; then
echo "[-] $object - failed"
FAILED=1
fi
done
if [ -z "$FAILED" ]; then
echo "[+] Build complete"
else
echo "[-] Build failed"
exit 1
fi

2
pupy/external/pykcp vendored

@ -1 +1 @@
Subproject commit a2f917e1bc100f6a5891966d3bbf057c1853a2a9
Subproject commit f926184f2771ceaf19f4ece8a5813b234562129f