mirror of
https://github.com/Gallopsled/pwntools.git
synced 2026-11-08 17:13:31 -10:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac386877d1 | ||
|
|
4f08b6d79c | ||
|
|
065c79d29c | ||
|
|
55456814fc | ||
|
|
3b2be2b2a7 | ||
|
|
0a3ac521ad | ||
|
|
326dd83321 | ||
|
|
510e247034 | ||
|
|
4d529cd543 | ||
|
|
e021f57806 | ||
|
|
b6cfec6284 | ||
|
|
5877f8e97e | ||
|
|
4ebcbee34b | ||
|
|
d25d62c126 | ||
|
|
5392611ed5 | ||
|
|
7c139c7179 | ||
|
|
da9ce55dfd | ||
|
|
9d394e0df1 | ||
|
|
f962d2bd21 | ||
|
|
667d290d9b | ||
|
|
766c4d8a7f | ||
|
|
189b1fb3c2 | ||
|
|
6c1b882b40 | ||
|
|
0c76348072 | ||
|
|
2f7d78bc64 | ||
|
|
646723fa8e | ||
|
|
e77915fba6 | ||
|
|
a02e8da1ea | ||
|
|
6979cb0d2b | ||
|
|
bc8942006b | ||
|
|
07c7b51f25 | ||
|
|
ee655cac60 | ||
|
|
b668815323 | ||
|
|
a26a1a1f35 | ||
|
|
ab42519e26 | ||
|
|
59b44b4fe6 | ||
|
|
f4f21f147b | ||
|
|
c06822571f | ||
|
|
383a4f4596 | ||
|
|
25d63da30e | ||
|
|
dd2ad30a51 | ||
|
|
d160f9b7c9 | ||
|
|
0bdbc2b8c3 | ||
|
|
d0c4d8488e | ||
|
|
f3968afbbb | ||
|
|
2d04acb867 | ||
|
|
62842e20f0 | ||
|
|
c929217947 | ||
|
|
ff08a859f8 | ||
|
|
ba24b440c5 | ||
|
|
b31adf27d0 | ||
|
|
20d27c651a | ||
|
|
ba7911651e | ||
|
|
cded6cda47 | ||
|
|
25941b52bb | ||
|
|
b79a750af6 | ||
|
|
eede2e2e1d | ||
|
|
2a59f5cf4c | ||
|
|
a3e82e27bb | ||
|
|
368a708663 | ||
|
|
4a7de306f0 | ||
|
|
69bbd0839a | ||
|
|
475ffa632e | ||
|
|
06db497901 | ||
|
|
5106c4eb75 | ||
|
|
08b7b190a7 | ||
|
|
8259d07207 | ||
|
|
ad2eb77cfa | ||
|
|
ec04c860c0 | ||
|
|
ffe4cf6807 | ||
|
|
673073f08d | ||
|
|
0e45f23af8 | ||
|
|
31cd98affe | ||
|
|
3e4a1bcc72 | ||
|
|
85c3074574 | ||
|
|
178e64a4f7 | ||
|
|
179476604e | ||
|
|
fc6e00d9f0 | ||
|
|
8b1f1dce84 | ||
|
|
8345bc3824 | ||
|
|
300f8e0c1a | ||
|
|
9ace73a977 | ||
|
|
fb16e158ec | ||
|
|
e519874947 | ||
|
|
2e90d05156 | ||
|
|
b6e3d5d8c5 | ||
|
|
0726d8d339 | ||
|
|
bd5a368754 | ||
|
|
602efd2790 | ||
|
|
2f7f0de984 | ||
|
|
45d2c11535 | ||
|
|
16b507e197 | ||
|
|
53f041a4d2 | ||
|
|
b2a5b76cf7 | ||
|
|
9cb438842c | ||
|
|
14f717b7b4 | ||
|
|
f792407c19 | ||
|
|
9c2f0f4e89 | ||
|
|
eb0bb6ea8d | ||
|
|
f46112e873 | ||
|
|
975844d83d | ||
|
|
466c0e4179 | ||
|
|
17e4f01976 | ||
|
|
fecd6f8222 | ||
|
|
7ba3a1b32f | ||
|
|
d1edd275d9 | ||
|
|
8f012947e9 | ||
|
|
36b05bac2b | ||
|
|
cb4991c41d | ||
|
|
65f18b6091 | ||
|
|
48616c633d | ||
|
|
323975f343 | ||
|
|
f65c258956 | ||
|
|
c928a0425e | ||
|
|
f5e16d3db6 | ||
|
|
d55874a6d3 | ||
|
|
0426d498d9 | ||
|
|
fefd48f341 | ||
|
|
132f48e6ee | ||
|
|
e205e17b6d | ||
|
|
d0267f3ee7 | ||
|
|
0c8006ca4e | ||
|
|
bd88c92991 | ||
|
|
12f1bb9126 | ||
|
|
3fa2c659fd | ||
|
|
a2c67e5075 | ||
|
|
54e722819b | ||
|
|
179a0656f5 | ||
|
|
58b2e36a1b | ||
|
|
24ae51dae4 | ||
|
|
14e68ec226 | ||
|
|
485dcede2c | ||
|
|
50acdbbe41 | ||
|
|
4e0e9d2acb | ||
|
|
bc7c8cd423 | ||
|
|
a8446bef47 | ||
|
|
afdcdec577 | ||
|
|
c13ff2cb08 | ||
|
|
a12d0b6a4c | ||
|
|
3dd6045488 | ||
|
|
cca9782424 | ||
|
|
5ce5339ab5 | ||
|
|
0cead77039 | ||
|
|
1d59a90fa8 | ||
|
|
ac017d97dc | ||
|
|
b584ca349a | ||
|
|
8b30700f92 | ||
|
|
7ed118763b | ||
|
|
5a370162e5 | ||
|
|
253ab78e4c | ||
|
|
e997c17397 | ||
|
|
0acc8ee499 | ||
|
|
d39f9a145e | ||
|
|
f14e0e5652 | ||
|
|
aaa83983ad | ||
|
|
1b76a27bd5 | ||
|
|
87491bf6dc | ||
|
|
b30835ec5b | ||
|
|
1241073391 | ||
|
|
cfcd79e169 | ||
|
|
706a784904 | ||
|
|
70c96330de | ||
|
|
cae3cddc07 | ||
|
|
5373dcdeed | ||
|
|
5d4bf3db6c | ||
|
|
fbfa54ad61 | ||
|
|
b323264032 | ||
|
|
332c9d2031 | ||
|
|
036397c861 | ||
|
|
dcf03fd44d | ||
|
|
df54bf2bb3 | ||
|
|
386e68691f | ||
|
|
2c841eaa21 | ||
|
|
22f170abc7 | ||
|
|
350610fbee | ||
|
|
c7b3852eae | ||
|
|
eaf6402198 | ||
|
|
d2c6184a00 | ||
|
|
e5645e7b53 | ||
|
|
09dbe0a54d | ||
|
|
0bd0de78f9 | ||
|
|
546061e577 | ||
|
|
5ebc8b5bb7 | ||
|
|
b83a6c7db8 | ||
|
|
5d9792fb4c | ||
|
|
1c54e347f2 | ||
|
|
2f597f41d4 | ||
|
|
7545dafffb | ||
|
|
3acec5421f | ||
|
|
620364dd1d | ||
|
|
b441cf967a | ||
|
|
76c21548db | ||
|
|
ad71d9235b | ||
|
|
2e5f8061b2 | ||
|
|
099404277e | ||
|
|
30c34b785a | ||
|
|
6c304d3511 | ||
|
|
dc297e17ae | ||
|
|
fa402ceb57 | ||
|
|
483adb8e2d | ||
|
|
76fe04e356 | ||
|
|
82312baba0 | ||
|
|
d101a775aa | ||
|
|
5fda6580e8 | ||
|
|
9185437626 | ||
|
|
bde40c36ae | ||
|
|
894b17e74a | ||
|
|
33b734cbc6 | ||
|
|
3e8454412e | ||
|
|
420f99c5d0 | ||
|
|
98052e4166 | ||
|
|
e971856c74 | ||
|
|
09ee73c31d | ||
|
|
0c4d1365e9 | ||
|
|
b3f941c3f5 | ||
|
|
67e11a9aeb | ||
|
|
7d5f8ca4b4 | ||
|
|
7695acc798 | ||
|
|
3f48a0b803 | ||
|
|
fd731154ff | ||
|
|
906bc94a5f | ||
|
|
db03e7de10 | ||
|
|
97e03fd29f | ||
|
|
09b8bb93a7 | ||
|
|
f9133b1680 | ||
|
|
8aa21bd99a | ||
|
|
e5b6aedd3d | ||
|
|
4b405c69b6 | ||
|
|
9af20c778f | ||
|
|
d1621dca87 | ||
|
|
31b047d29b | ||
|
|
39970c3847 | ||
|
|
e0c65c9d6d | ||
|
|
59d0cd2eeb | ||
|
|
8d11fb8594 | ||
|
|
aec3fa6879 | ||
|
|
ab6602407e | ||
|
|
42ab0c985d | ||
|
|
b215828133 | ||
|
|
e3af4ce6a7 | ||
|
|
96c6edcc37 | ||
|
|
b198ec8633 | ||
|
|
c8a87381e8 | ||
|
|
548e033e7e | ||
|
|
fc097f3446 | ||
|
|
eb92a95134 | ||
|
|
c706461f10 | ||
|
|
b0ad5eb915 | ||
|
|
94f88cc8ba | ||
|
|
1e414afbeb | ||
|
|
869ec42082 | ||
|
|
4893819b4c | ||
|
|
fb1b952769 | ||
|
|
859380285f | ||
|
|
2af55c9bc3 | ||
|
|
4725b1be96 | ||
|
|
5af5f0c55d | ||
|
|
e84f395c97 | ||
|
|
fbf51ad96e | ||
|
|
52433339ec | ||
|
|
f277d5502f | ||
|
|
794122ec13 | ||
|
|
65b266e9b3 | ||
|
|
ca6eddc235 | ||
|
|
8793decd1c | ||
|
|
628aaabd04 | ||
|
|
3544167f26 | ||
|
|
9cca9c989b | ||
|
|
dacdd397ab | ||
|
|
627ed5cbd5 | ||
|
|
3fb64f9fe0 | ||
|
|
254958bae9 | ||
|
|
2cd5aadf9d | ||
|
|
6ebcc6f3a2 | ||
|
|
1c47a30446 | ||
|
|
5b8ccb60a6 | ||
|
|
89fc74facf | ||
|
|
efc531a2a9 | ||
|
|
8b959c9ede | ||
|
|
68051f9987 | ||
|
|
3636657ca0 | ||
|
|
f282ef8bbc | ||
|
|
57e9bf58a5 | ||
|
|
0ce21d9b45 | ||
|
|
89649fbeb0 | ||
|
|
5924c0f340 | ||
|
|
2f9f10c182 | ||
|
|
d7c98c4819 | ||
|
|
bebc84522d | ||
|
|
e7875c78bc | ||
|
|
0a37694436 | ||
|
|
742a11bfdc | ||
|
|
1e7262ce31 | ||
|
|
d733cf6560 | ||
|
|
3818dda9d9 | ||
|
|
18c4a49aa3 | ||
|
|
77f7a362d0 | ||
|
|
738fadc016 | ||
|
|
b97f30f36f | ||
|
|
de05e7a4b8 | ||
|
|
5fe024838b | ||
|
|
cd828d6bca | ||
|
|
b60103b839 | ||
|
|
5acc4c8ec3 | ||
|
|
a5c2b9276a | ||
|
|
913a3eba9e | ||
|
|
041e62bf0b | ||
|
|
e61f571f7c | ||
|
|
36d00b615d | ||
|
|
25d340b5c5 | ||
|
|
8f06c1f90f | ||
|
|
ae6a0745ff | ||
|
|
1d924af9d2 | ||
|
|
fed432877c | ||
|
|
46261091dd | ||
|
|
c356b69a13 | ||
|
|
6cff484b8c | ||
|
|
8314dff386 | ||
|
|
dc40ac1117 | ||
|
|
288b9668b7 | ||
|
|
3c0697b81e | ||
|
|
6e4e46386f | ||
|
|
9b179567da | ||
|
|
b20e17dd13 | ||
|
|
3dcfafc0de | ||
|
|
348bcac0ff | ||
|
|
a43c3b4967 | ||
|
|
40bf991153 | ||
|
|
8f98c01b77 | ||
|
|
18a8cfb88d | ||
|
|
2acdeef320 | ||
|
|
23c09b4b1b | ||
|
|
84c71d6b07 | ||
|
|
c6aa6bccb8 | ||
|
|
041c665185 | ||
|
|
70f9c0305d | ||
|
|
66e41bd862 | ||
|
|
5140d03b4d | ||
|
|
b016179ccc | ||
|
|
efaea581a1 | ||
|
|
f4a72da40e | ||
|
|
6376d07266 | ||
|
|
ea94ee4ca5 | ||
|
|
452605e854 | ||
|
|
dea8f00c01 | ||
|
|
b9d6b27b4e | ||
|
|
300ef0b462 | ||
|
|
6e79272e8d | ||
|
|
d65991d402 | ||
|
|
de94449a87 | ||
|
|
faeb57b35c | ||
|
|
e1332d277c | ||
|
|
e4c2a48696 | ||
|
|
fcf2842d87 | ||
|
|
422dccd8da | ||
|
|
abd08a94ea | ||
|
|
e877f7455a | ||
|
|
e635bcfea7 | ||
|
|
12b60447da | ||
|
|
77da84c5a8 | ||
|
|
2663762a9a |
No files matched your search
@@ -0,0 +1,9 @@
|
||||
# Pwntools Issue Template
|
||||
|
||||
Thanks for contributing to Pwntools!
|
||||
|
||||
When reporting an issue, be sure that you are running the latest released version of pwntools (`pip install --upgrade pwntools`).
|
||||
|
||||
Please verify that your issue occurs on 64-bit Ubuntu 14.04. You can use the Dockerfile in `extra/docker/Dockerfile` to save time.
|
||||
|
||||
If possible, provide a proof-of-concept which demonstrates the problem. Include any binaries or scripts necessary to reproduce the issue, and please include the full debug output via setting the environment variable `PWNLIB_DEBUG=1`.
|
||||
@@ -0,0 +1,27 @@
|
||||
# Pwntools Pull Request
|
||||
|
||||
Thanks for contributing to Pwntools! Take a moment to look at [`CONTRIBUTING.md`][contributing] to make sure you're familiar with Pwntools development.
|
||||
|
||||
Please provide a high-level explanation of what this pull request is for.
|
||||
|
||||
## Testing
|
||||
|
||||
Pull Requests that introduce new code should try to add doctests for that code. See [`TESTING.md`][testing] for more information.
|
||||
|
||||
## Target Branch
|
||||
|
||||
Depending on what the PR is for, it needs to target a different branch.
|
||||
|
||||
You can always [change the branch][change] after you create the PR if it's against the wrong branch.
|
||||
|
||||
| Branch | Type of PR |
|
||||
| -------- | ---------------------------------------------------------------- |
|
||||
| `dev` | New features, and enhancements
|
||||
| `dev` | Documentation fixes and new tests
|
||||
| `stable` | Bug fixes that affect the current `stable` branch
|
||||
| `beta` | Bug fixes that affect the current `beta` branch, but not `stable`
|
||||
| `dev` | Bug fixes for code that has never been released
|
||||
|
||||
[contributing]: https://github.com/Gallopsled/pwntools/blob/dev/CONTRIBUTING.md
|
||||
[testing]: https://github.com/Gallopsled/pwntools/blob/dev/TESTING.md
|
||||
[change]: https://github.com/blog/2224-change-the-base-branch-of-a-pull-request
|
||||
@@ -14,3 +14,4 @@ dist
|
||||
*.egg-info
|
||||
*.core
|
||||
.coverage
|
||||
.tox
|
||||
+20
-6
@@ -5,6 +5,15 @@ addons:
|
||||
packages:
|
||||
- gcc-multilib
|
||||
- gcc-4.6-arm-linux-gnueabihf
|
||||
- lib32stdc++6
|
||||
- ash
|
||||
- bash
|
||||
- dash
|
||||
- ksh
|
||||
- mksh
|
||||
- zsh
|
||||
- pandoc
|
||||
- gdb
|
||||
cache:
|
||||
- pip
|
||||
- directories:
|
||||
@@ -13,14 +22,16 @@ cache:
|
||||
- /home/travis/virtualenv/python2.7.9/bin/
|
||||
python:
|
||||
- "2.7"
|
||||
after_success:
|
||||
- coveralls
|
||||
before_install:
|
||||
- source .travis_install.sh
|
||||
- source .travis_ssh_setup.sh
|
||||
- echo $-
|
||||
- source travis/install.sh
|
||||
- source travis/ssh_setup.sh
|
||||
- echo $-
|
||||
install:
|
||||
- pip install -e .
|
||||
- pip install -r docs/requirements.txt
|
||||
- pip install --upgrade pip
|
||||
- pip install --upgrade appdirs # https://github.com/ActiveState/appdirs/issues/89#issuecomment-282326570
|
||||
- pip install --upgrade --editable .
|
||||
- pip install --upgrade --requirement docs/requirements.txt
|
||||
before_script:
|
||||
- PWNLIB_NOTERM=1 python -c 'from pwn import *; print pwnlib.term.term_mode'
|
||||
- PWNLIB_NOTERM=1 python -c 'from pwn import *; print pwnlib.term.term_mode'
|
||||
@@ -28,3 +39,6 @@ before_script:
|
||||
- PWNLIB_NOTERM=1 python -c 'from pwn import *; print pwnlib.term.term_mode'
|
||||
script:
|
||||
- PWNLIB_NOTERM=1 coverage run -m sphinx -b doctest docs/source docs/build/doctest
|
||||
after_success:
|
||||
- coveralls
|
||||
- source travis/update_demo.sh
|
||||
@@ -1,90 +0,0 @@
|
||||
#!/usr/bin/env bash -e
|
||||
set -e
|
||||
local_deb_extract()
|
||||
{
|
||||
wget $1
|
||||
ar vx *.deb
|
||||
tar xvf data.tar.*
|
||||
rm -f *.tar.* *deb*
|
||||
}
|
||||
|
||||
get_binutils()
|
||||
{
|
||||
BINUTILS_PREFIX='https://launchpad.net/~pwntools/+archive/ubuntu/binutils/+files/binutils-'
|
||||
BINUTILS_SUFFIX='-linux-gnu_2.22-6ubuntu1.1cross0.11pwntools12~precise_amd64.deb'
|
||||
local_deb_extract "${BINUTILS_PREFIX}${1}${BINUTILS_SUFFIX}"
|
||||
}
|
||||
|
||||
get_qemu()
|
||||
{
|
||||
echo "Installing qemu"
|
||||
QEMU_INDEX='http://packages.ubuntu.com/en/yakkety/amd64/qemu-user-static/download'
|
||||
QEMU_URL=$(curl "$QEMU_INDEX" | grep kernel.org | grep -Eo 'http.*\.deb')
|
||||
local_deb_extract "$QEMU_URL"
|
||||
}
|
||||
|
||||
setup_travis()
|
||||
{
|
||||
export PATH=$PWD/usr/bin:$PATH
|
||||
export LD_LIBRARY_PATH=$PWD/usr/lib
|
||||
|
||||
# Install libbfd-multiarch and libopcodes-multiarch if not found in the cache
|
||||
if [ ! -f usr/lib/libbfd-2.22-multiarch.so ];
|
||||
then
|
||||
# Install the multiarch binutils
|
||||
local_deb_extract http://mirrors.mit.edu/ubuntu/pool/universe/b/binutils/binutils-multiarch_2.22-6ubuntu1_amd64.deb
|
||||
pushd usr/lib
|
||||
ln -sf libbfd-2.22-multiarch.so libbfd-2.22.so
|
||||
ln -sf libopcodes-2.22-multiarch.so libopcodes-2.22.so
|
||||
popd
|
||||
fi
|
||||
|
||||
# Install/upgrade qemu
|
||||
if ! (which qemu-arm-static && qemu-arm-static -version | grep 2.6.1); then
|
||||
get_qemu
|
||||
fi
|
||||
|
||||
# Install our custom binutils
|
||||
which arm-linux-gnu-as || get_binutils arm
|
||||
which mips-linux-gnu-as || get_binutils mips
|
||||
which powerpc-linux-gnu-as || get_binutils powerpc
|
||||
|
||||
# Test that the installs worked
|
||||
which arm-linux-gnu-as
|
||||
which mips-linux-gnu-as
|
||||
which powerpc-linux-gnu-as
|
||||
which qemu-arm-static
|
||||
|
||||
# Get rid of files we don't want cached
|
||||
rm -rf usr/share
|
||||
}
|
||||
|
||||
setup_linux()
|
||||
{
|
||||
sudo apt-get install -y software-properties-common openssh-server libncurses5-dev libncursesw5-dev
|
||||
sudo apt-add-repository --yes ppa:pwntools/binutils
|
||||
sudo apt-get update
|
||||
sudo apt-get install binutils-arm-linux-gnu binutils-mips-linux-gnu binutils-powerpc-linux-gnu
|
||||
}
|
||||
|
||||
setup_osx()
|
||||
{
|
||||
brew update
|
||||
brew install binutils
|
||||
brew install capstone
|
||||
}
|
||||
|
||||
if [[ "$USER" == "travis" ]]; then
|
||||
setup_travis
|
||||
elif [[ "$USER" == "shippable" ]]; then
|
||||
sudo apt-get update
|
||||
sudo apt-get install openssh-server gcc-multilib
|
||||
sudo /usr/sbin/sshd -f /etc/ssh/sshd_config &
|
||||
setup_travis
|
||||
elif [[ "$(uname)" == "Darwin" ]]; then
|
||||
setup_osx
|
||||
elif [[ "$(uname)" == "Linux" ]]; then
|
||||
setup_linux
|
||||
fi
|
||||
|
||||
dpkg -l
|
||||
@@ -1,56 +0,0 @@
|
||||
#!/usr/bin/env bash
|
||||
#
|
||||
# Install a demo user for SSH purposes
|
||||
#
|
||||
# All of the "conditional sudo" is to do container-based builds on
|
||||
# Travis which are much, much faster.
|
||||
set -e
|
||||
|
||||
U=travis
|
||||
H=/home/$U
|
||||
|
||||
USUDO()
|
||||
{
|
||||
if [[ "$USER" == "travis" ]];
|
||||
then
|
||||
$*
|
||||
else
|
||||
sudo -u $U $*
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
if [[ "$USER" == "travis" ]];
|
||||
then
|
||||
rm -f ~/.ssh/*
|
||||
else
|
||||
# Create the new user account
|
||||
# Disable password login for the user, and ensure the account is not locked
|
||||
sudo useradd -m $U
|
||||
sudo passwd --delete --unlock $U
|
||||
fi
|
||||
|
||||
# Generate a new key so that we can log into it
|
||||
ssh-keygen -t rsa -f ~/.ssh/$U -N ''
|
||||
|
||||
# Load the public key into a memory for below
|
||||
pubkey=$(cat ~/.ssh/$U.pub)
|
||||
|
||||
# Set the authorized_keys entry to only permit login from localhost,
|
||||
# and only with
|
||||
USUDO mkdir $H/.ssh || true
|
||||
USUDO tee -a $H/.ssh/authorized_keys <<EOF
|
||||
from="127.0.0.1" $pubkey
|
||||
EOF
|
||||
|
||||
# In the pwntools examples, we ssh to 'example.pwnme'
|
||||
# Set up an SSH config entry to make this actually work
|
||||
cat >> ~/.ssh/config <<EOF
|
||||
|
||||
Host example.pwnme
|
||||
User $U
|
||||
HostName 127.0.0.1
|
||||
IdentityFile ~/.ssh/$U
|
||||
EOF
|
||||
|
||||
ssh -o "StrictHostKeyChecking no" -vvvv [email protected] id
|
||||
+321
-10
@@ -3,30 +3,341 @@
|
||||
This changelog only includes added major features and changes. Bugfixes and
|
||||
minor changes are omitted.
|
||||
|
||||
## 3.0.4 (September 19, 2016)
|
||||
## Release History
|
||||
|
||||
**Current release**
|
||||
The table below shows which release corresponds to each branch, and what date the version was released.
|
||||
|
||||
| Version | Branch | Release Date |
|
||||
| ---------------- | -------- | ---------------------- |
|
||||
| [3.7.0](#350) | `dev` | Jun 17, 2017 (planned)
|
||||
| [3.6.0](#350) | `beta` | May 6, 2017 (planned)
|
||||
| [3.5.1](#351) | `stable` | Apr 15, 2017
|
||||
| [3.5.0](#350) | | Mar 26, 2017
|
||||
| [3.4.1](#341) | | Feb 17, 2017
|
||||
| [3.4.0](#340) | | Feb 13, 2017
|
||||
| [3.3.4](#334) | | Jan 12, 2016
|
||||
| [3.3.3](#333) | | Jan 10, 2016
|
||||
| [3.3.2](#332) | | Jan 10, 2016
|
||||
| [3.3.1](#331) | | Jan 10, 2016
|
||||
| [3.3.0](#330) | | Dec 24, 2016
|
||||
| [3.2.1](#321) | | Dec 24, 2016
|
||||
| [3.2.0](#320) | | Nov 12, 2016
|
||||
| [3.1.1](#311) | | Oct 23, 2016
|
||||
| [3.1.0](#310) | | Oct 2, 2016
|
||||
| [3.0.4](#304) | | Sept 19, 2016
|
||||
| [3.0.3](#303) | | Sept 18, 2016
|
||||
| [3.0.2](#302) | | Sept 6, 2016
|
||||
| [3.0.1](#301) | | Aug 20, 2016
|
||||
| [3.0.0](#300) | | Aug 20, 2016
|
||||
| [2.2.0](#220) | | Jan 5, 2015
|
||||
|
||||
## 3.7.0
|
||||
|
||||
To be on Jun 17, 2017.
|
||||
|
||||
## 3.6.0
|
||||
|
||||
To be released on May 6, 2017.
|
||||
|
||||
- [#895][895] Added a Dockerfile to simplify testing setup and allow testing on OSX
|
||||
- [#897][897] Fixed some incorrect AArch64 syscals
|
||||
- [#893][893] Added the `pwnlib.config` module
|
||||
+ Configuration options can now be set in `~/.pwn.conf`
|
||||
+ This replaces the old, **undocumented** mechanism for changing logging colors. Only @br0ns and @ebeip90 were likely using this.
|
||||
+ More information is available in the documentation [here](http://docs.pwntools.com/en/dev/config.html).
|
||||
- [#899][899] Pwntools now uses Unicorn Engine to emulate PLT instructions to ensure correct mapping of PIE / RELRO binaries.
|
||||
- [#904][904] Enhancements to the accuracy of the `pwn checksec` command.
|
||||
- [#905][905] Added a `pwn debug` command-line utility which automates the process of `gdb.attach(process(...))` to spawn GDB
|
||||
+ More information is available in the documentation [here](http://docs.pwntools.com/en/dev/commandline.html#pwn-debug)
|
||||
- [#919][919] Added a `pwn template` command-line utility to simplify the process of bootstrapping a new exploit.
|
||||
+ More information is available in the documentation [here](http://docs.pwntools.com/en/dev/commandline.html#pwn-template).
|
||||
|
||||
[895]: https://github.com/Gallopsled/pwntools/pull/895
|
||||
[897]: https://github.com/Gallopsled/pwntools/pull/897
|
||||
[893]: https://github.com/Gallopsled/pwntools/pull/893
|
||||
[899]: https://github.com/Gallopsled/pwntools/pull/899
|
||||
[904]: https://github.com/Gallopsled/pwntools/pull/904
|
||||
[905]: https://github.com/Gallopsled/pwntools/pull/905
|
||||
[919]: https://github.com/Gallopsled/pwntools/pull/919
|
||||
|
||||
## 3.5.1
|
||||
|
||||
- [#945][945] Speed up ssh via caching checksec results (fixes [#944][944])
|
||||
- [#950][950] Fixes a bug where setting `context.arch` does not have an effect on `adb.compile()` output architecture
|
||||
|
||||
[944]: https://github.com/Gallopsled/pwntools/issues/944
|
||||
[945]: https://github.com/Gallopsled/pwntools/pull/945
|
||||
[950]: https://github.com/Gallopsled/pwntools/pull/950
|
||||
|
||||
## 3.5.0
|
||||
|
||||
- [b584ca3][b584ca3] Fixed an issue running `setup.py` on ARM
|
||||
- [#822][822] Enabled relative leaks with `MemLeak`
|
||||
+ This should be useful for e.g. heap-relative leaks
|
||||
- [#832][832] Changed all internal imports to use absolute imports (no functional changes)
|
||||
- [a12d0b6][a12d0b6] Move `STDOUT`, `PIPE`, `PTY` constants to globals
|
||||
+ `process(..., stdin=process.PTY)` --> `process(..., stdin=PTY)`
|
||||
- [#828][828] Use `PR_SET_PTRACER` for all `process()` and `ssh.process()` instances
|
||||
+ This simplifies debugging on systems with YAMA ptrace enabled
|
||||
- Various documentation enhancements
|
||||
+ In particular, the [gdb][gdb], [elf][elf], and [ssh][ssh] docs are much better
|
||||
- [#833][833] Performance enhancements for `adb` module
|
||||
- [d0267f3][d0267f3] `packing.fit()` now treats large offsets as cyclic patterns (e.g. `0x61616161` behaves the same as `"aaaa"`)
|
||||
- [#835][835] Added `ssh.checksec`
|
||||
+ Reports the kernel version and other relevant information on connection
|
||||
- [#857][857] Slightly shortened `execve` shellcode
|
||||
- [300f8e0][300f8e0] Slightly speed up processing of large ELF files
|
||||
- [#861][861] Adds support for extracting `IKCONFIG` configs from Linux kernel images, and extends `checksec` to report on any insecure configurations discovered
|
||||
- [#871][871] Moves all of the basic syscall templates to `shellcraft/common` and exposes them via symlinks. Closed [#685][685]
|
||||
+ Should not have any visible effects from any documented APIs
|
||||
+ `shellcraft.arch.os.syscall_function()` still works the same
|
||||
+ We now have the ability to differentiate between the `connect` syscall, and a TCP `connect` helper
|
||||
- [#887][887] `sh_string` now returns a quoted empty string `''` rather than just an empty string
|
||||
- [#839][839] Exposes a huge amount of functionality via corefiles which was not previously availble. See the [docs][corefile_docs] for examples.
|
||||
+ `process().corefile` will automatically instantiate a Corefile for the process
|
||||
+ QEMU-emulated processes are supported
|
||||
+ Native processes are supported, including extraction of coredumps from `apport` crash logs
|
||||
+ Native processes can be dumped *while running*, in a manner similar to `GDB`'s `gcore` script
|
||||
- [#875][857] Added [documentation][aarch64] (and tests) for AArch64 shellcode
|
||||
- [#882][882] The `ROP` class now respects `context.bytes` instead of using the hard-coded value of `4` (fixed [#879][879])
|
||||
- [#869][869] Added several fields to the `process` class (`uid`, `gid`, `suid`, `sgid`) which are recorded at execution time, based on the file permissions
|
||||
- [#868][868] Changed the way that `ssh.process()` works internally, and it now returns a more specialized class, `ssh_process`.
|
||||
+ Added `ssh_process.corefile` for fetching remote corefiles
|
||||
+ Added `ssh_process.ELF` for getting an ELF of the remote executable
|
||||
+ The `uid`, `gid`, and `suid`, and `sgid` which are recorded at execution time, based on the file permissions
|
||||
- [#865][865] Fixes `ELF.read` to support contiguous memory reads across non-contiguous file-backed segments
|
||||
- [#862][862] Adds a `symlink=` argument to `ssh.set_working_directory`, which will automatically symlink all of the files in the "old" working directory into the "new" working directory
|
||||
|
||||
[ssh]: http://docs.pwntools.com/en/dev/tubes/ssh.html
|
||||
[gdb]: http://docs.pwntools.com/en/dev/gdb.html
|
||||
[elf]: http://docs.pwntools.com/en/dev/elf.html
|
||||
[corefile_docs]: http://docs.pwntools.com/en/dev/elf/corefile.html
|
||||
[aarch64]: http://docs.pwntools.com/en/dev/shellcraft/aarch64.html
|
||||
|
||||
[685]: https://github.com/Gallopsled/pwntools/pull/685
|
||||
[822]: https://github.com/Gallopsled/pwntools/pull/822
|
||||
[828]: https://github.com/Gallopsled/pwntools/pull/828
|
||||
[832]: https://github.com/Gallopsled/pwntools/pull/832
|
||||
[833]: https://github.com/Gallopsled/pwntools/pull/833
|
||||
[835]: https://github.com/Gallopsled/pwntools/pull/835
|
||||
[839]: https://github.com/Gallopsled/pwntools/pull/839
|
||||
[857]: https://github.com/Gallopsled/pwntools/pull/857
|
||||
[861]: https://github.com/Gallopsled/pwntools/pull/861
|
||||
[862]: https://github.com/Gallopsled/pwntools/pull/862
|
||||
[865]: https://github.com/Gallopsled/pwntools/pull/865
|
||||
[868]: https://github.com/Gallopsled/pwntools/pull/868
|
||||
[869]: https://github.com/Gallopsled/pwntools/pull/869
|
||||
[871]: https://github.com/Gallopsled/pwntools/pull/871
|
||||
[875]: https://github.com/Gallopsled/pwntools/pull/857
|
||||
[879]: https://github.com/Gallopsled/pwntools/issues/879
|
||||
[882]: https://github.com/Gallopsled/pwntools/pull/882
|
||||
[887]: https://github.com/Gallopsled/pwntools/pull/887
|
||||
|
||||
|
||||
[b584ca3]: https://github.com/Gallopsled/pwntools/commit/b584ca3
|
||||
[a12d0b6]: https://github.com/Gallopsled/pwntools/commit/a12d0b6
|
||||
[d0267f3]: https://github.com/Gallopsled/pwntools/commit/d0267f3
|
||||
[300f8e0]: https://github.com/Gallopsled/pwntools/commit/300f8e0
|
||||
|
||||
## 3.4.1
|
||||
|
||||
- [#894][894] Fix a bug when using `gdb.debug()` over ssh.
|
||||
- [e021f57][e021f57] Fix a bug ([#891][891]) in `rop` when needing to insert padding to fix alignment
|
||||
|
||||
[e021f57]: https://github.com/Gallopsled/pwntools/commit/e021f57
|
||||
[894]: https://github.com/Gallopsled/pwntools/pull/894
|
||||
[891]: https://github.com/Gallopsled/pwntools/issues/891
|
||||
|
||||
## 3.4.0
|
||||
|
||||
- [#800][800] Add `shell=` option to `ssh.process()`
|
||||
- [#806][806] Add `context.buffer_size` for fine-tuning `tube` performance
|
||||
+ Also adds `buffer_fill_size=` argument for all tubes
|
||||
- [b83a6c7][b83a6c7] Fix undocumented `process.leak` function
|
||||
- [546061e][546061e] Modify `coredump_filter` of all spawned processes, so that core dumps are more complete
|
||||
- [#809][809] Add several functions to `adb` (`unlink`, `mkdir`, `makedirs`, `isdir`, `exists`)
|
||||
- [#817][817] Make disconnection detection more robust
|
||||
|
||||
[800]: https://github.com/Gallopsled/pwntools/pull/800
|
||||
[806]: https://github.com/Gallopsled/pwntools/pull/806
|
||||
[809]: https://github.com/Gallopsled/pwntools/pull/809
|
||||
[817]: https://github.com/Gallopsled/pwntools/pull/817
|
||||
[5d9792f]: https://github.com/Gallopsled/pwntools/commit/5d9792f
|
||||
[b83a6c7]: https://github.com/Gallopsled/pwntools/commit/b83a6c7
|
||||
[546061e]: https://github.com/Gallopsled/pwntools/commit/546061e
|
||||
|
||||
## 3.3.4
|
||||
|
||||
- [#850][850] and [#846][846] fix issues with `hexdump` and the `phd` command-line utility, when using pipes (e.g. `echo foo | phd`)
|
||||
- [#852][852] Fixes register ordering in `regsort`
|
||||
- [#853][853] Fixes the registers restored in `shellcraft.amd64.popad`
|
||||
|
||||
[846]: https://github.com/gallopsled/pwntools/pull/846
|
||||
[850]: https://github.com/gallopsled/pwntools/pull/850
|
||||
[852]: https://github.com/gallopsled/pwntools/pull/852
|
||||
[853]: https://github.com/gallopsled/pwntools/pull/853
|
||||
|
||||
## 3.3.3
|
||||
|
||||
- [#843][843] fixed a bug in `amd64.mov`.
|
||||
|
||||
[843]: https://github.com/gallopsled/pwntools/pull/843
|
||||
|
||||
## 3.3.2
|
||||
|
||||
- [#840][840] fixed a regression introduced by [#837][837].
|
||||
|
||||
[840]: https://github.com/gallopsled/pwntools/pull/840
|
||||
|
||||
## 3.3.1
|
||||
|
||||
- [#833][833] Fixed a performance-impacting bug in the adb module.
|
||||
- [#837][837] Fixed a bug([#836][836]) causing `hexdump(cyclic=True)` to throw an exception.
|
||||
|
||||
[833]: https://github.com/Gallopsled/pwntools/pull/833
|
||||
[837]: https://github.com/Gallopsled/pwntools/pull/837
|
||||
[836]: https://github.com/Gallopsled/pwntools/issues/836
|
||||
|
||||
## 3.3.0
|
||||
|
||||
- [b198ec8][b198ec8] Added `tube.stream()` function, which is like `tube.interact()` without a prompt or keyboard input.
|
||||
+ Effectively, this is similar to `cat file` and just prints data as fast as it is received.
|
||||
- [aec3fa6][aec3fa6] Disable update checks against GitHub
|
||||
+ These checks frequently broke due to GitHub query limits
|
||||
- [#757][757] Fixed `adb.wait_for_device()` re-use of the same connection
|
||||
- [f9133b1][f9133b1] Add a `STDERR` magic argument to make logging go to `stderr` instead of `stdout`
|
||||
+ Usage is e.g. `python foo.py STDERR` or `PWNLIB_STDERR=1 python foo.py`
|
||||
+ Also adds `context.log_console` to log to any file or terminal
|
||||
- [67e11a9][67e11a9] Add faster error checking to `cyclic()` when provided very large values
|
||||
- [5fda658][5fda658] Expose BitPolynom in `globals()`
|
||||
- [#765][765] Added `-d` option for hex-escaped output for `shellcraft` command-line tool
|
||||
- [#772][772] Fixed bash completion regressions
|
||||
- [30c34b7][30c34b7] Fix `ROP.call()` with `Function` objects from `ELF.functions`
|
||||
- [fa402ce][fa402ce] Add `adb.uptime` and `adb.boot_time`
|
||||
- [82312ba][82312ba] Add `cyclic_metasploit` and `cyclic_metasploit_find`
|
||||
|
||||
[757]: https://github.com/Gallopsled/pwntools/pull/757
|
||||
[765]: https://github.com/Gallopsled/pwntools/pull/765
|
||||
[772]: https://github.com/Gallopsled/pwntools/pull/772
|
||||
[b198ec8]: https://github.com/Gallopsled/pwntools/commit/b198ec8
|
||||
[aec3fa6]: https://github.com/Gallopsled/pwntools/commit/aec3fa6
|
||||
[f9133b1]: https://github.com/Gallopsled/pwntools/commit/f9133b1
|
||||
[67e11a9]: https://github.com/Gallopsled/pwntools/commit/67e11a9
|
||||
[5fda658]: https://github.com/Gallopsled/pwntools/commit/5fda658
|
||||
[30c34b7]: https://github.com/Gallopsled/pwntools/commit/30c34b7
|
||||
[fa402ce]: https://github.com/Gallopsled/pwntools/commit/fa402ce
|
||||
[82312ba]: https://github.com/Gallopsled/pwntools/commit/82312ba
|
||||
|
||||
## 3.2.1
|
||||
|
||||
Multiple bug fixes.
|
||||
|
||||
- [#783][783] Fix `adb.uninstall` typo
|
||||
- [#787][787] Added error handling for `ssh.process` argument `preexec_fn`
|
||||
- [#793][793] Fixed progress message in `remote()` when connections failed
|
||||
- [#802][802] Fixed partition listing in `adb.partitions`, which accidentally shelled out to the `adb` binary
|
||||
- [#804][804] Fix error message for 32-bit distributions
|
||||
- [#805][805] Fix exception in `Core.segments` when a segment has no name
|
||||
- [#811][811] Fixes and performance improvements for `adb.wait_for_device()`
|
||||
- [#813][813] Fixed a release script
|
||||
- [#814][814] Fixed exceptions thrown if the `$HOME` directory is not writable
|
||||
- [#815][815] Properly handle `None` in `MemLeak`
|
||||
|
||||
[783]: https://github.com/Gallopsled/pwntools/pull/783
|
||||
[787]: https://github.com/Gallopsled/pwntools/pull/787
|
||||
[793]: https://github.com/Gallopsled/pwntools/pull/793
|
||||
[802]: https://github.com/Gallopsled/pwntools/pull/802
|
||||
[804]: https://github.com/Gallopsled/pwntools/pull/804
|
||||
[805]: https://github.com/Gallopsled/pwntools/pull/805
|
||||
[811]: https://github.com/Gallopsled/pwntools/pull/811
|
||||
[813]: https://github.com/Gallopsled/pwntools/pull/813
|
||||
[814]: https://github.com/Gallopsled/pwntools/pull/814
|
||||
[815]: https://github.com/Gallopsled/pwntools/pull/815
|
||||
|
||||
## 3.2.0
|
||||
|
||||
- [#695][695] Fixed a performance regression in `phd`.
|
||||
- [452605e][452605e] Fixed [#629][629] related to correct removal of temporary files.
|
||||
- [ea94ee4][ea94ee4] Disallows semi-colons in for the `run_in_terminal` function, since it did not work properly in all cases.
|
||||
- [6376d07][6376d07] Added the mips shellcode `pushstr_array`.
|
||||
- [#700][700] Added missing MIPS shellcode documentation to readthedocs, and enabled unit tests
|
||||
- [#701][701] Command line tools refactored to have a common `pwn` entry point.
|
||||
+ Added an option to *not* install the traditional `asm`, `disasm`, `checksec`, etc scripts
|
||||
+ All existing tools can be accessed from the `pwn` command (e.g. `pwn asm nop`).
|
||||
- [#704][704] The `process` object has a new, optional argument `alarm` for setting a `SIGALRM` timeout for processes.
|
||||
- [#705][705] Added the Android Emulator to the test suite and Travis CI.
|
||||
+ Android Emulator is now required for the full test suite
|
||||
+ Android Emulator tests are skipped if no Android-related changes are detected
|
||||
- [#711][711] `DynELF` has a new attribute, `heap`, which leaks the current `brk` address (heap base). This is useful for finding heap allocations with dlmalloc-derived allocators like those used by Glibc.
|
||||
- [#717][717] `sh_string` was rewritten to emit more compact and compatible strings
|
||||
+ This was achieved by embedding single-quoted non-printable literals
|
||||
+ Much more testing was added
|
||||
+ Emitted strings are no longer copy-paste compatible, but work fine with e.g. `tubes` module and the default `subprocess` module
|
||||
- [#709][709] The `adb` module now directly talks to the `adb` server process via a new module, `adb.protocol`
|
||||
+ Removes the need to shell out to `adb`
|
||||
+ Avoids version-compatibility issues with `adb` server vs. client
|
||||
- [#703][703] Added new methods to `adb`
|
||||
+ `install` - Installs an APK
|
||||
+ `uninstall` - Uninstalls a package
|
||||
+ `packages` - Lists installed packages
|
||||
- [4893819][4893819] Modified `shellcraft.sh` on all platforms to provide `argv[0]` and set `argc==1`
|
||||
+ This is needed for systems which have Busybox or other minimal shell for `/bin/sh` which does not behave well with `argc==0` or `argv[0]==NULL`.
|
||||
- [1e414af][1e414af] Added `connect()` alias for `remote()`
|
||||
+ For example, `io=connect('google.com', 80)`
|
||||
+ This also works with `tcp(...)` and `udp(...)` aliases
|
||||
- [869ec42][869ec42] Added `ssh.read()` and `ssh.write()` aliases
|
||||
- [2af55c9][2af55c9] `AdbDevice` objects exposed via e.g. `adb.devices()` now offer scoped access to all `adb` module properties
|
||||
+ It is now possible to e.g. `map(lambda d: d.process(['id']).recvall(), adb.devices())`
|
||||
|
||||
|
||||
[629]: https://github.com/Gallopsled/pwntools/issues/629
|
||||
[695]: https://github.com/Gallopsled/pwntools/pull/695
|
||||
[700]: https://github.com/Gallopsled/pwntools/pull/700
|
||||
[701]: https://github.com/Gallopsled/pwntools/pull/701
|
||||
[704]: https://github.com/Gallopsled/pwntools/pull/704
|
||||
[711]: https://github.com/Gallopsled/pwntools/pull/711
|
||||
[717]: https://github.com/Gallopsled/pwntools/pull/717
|
||||
[709]: https://github.com/Gallopsled/pwntools/pull/709
|
||||
[705]: https://github.com/Gallopsled/pwntools/pull/705
|
||||
[703]: https://github.com/Gallopsled/pwntools/pull/703
|
||||
[452605e]: https://github.com/Gallopsled/pwntools/commit/452605e854f4870ef5ccfdf7fb110dfd75c50feb
|
||||
[ea94ee4]: https://github.com/Gallopsled/pwntools/commit/ea94ee4ca5a8060567cc9bd0dc33796a89ad0b95
|
||||
[6376d07]: https://github.com/Gallopsled/pwntools/commit/6376d072660fb2250f48bd22629bbd7e3c61c758
|
||||
[1e414af]: https://github.com/Gallopsled/pwntools/commit/1e414afbeb3a01242f4918f111febaa63b640eb7
|
||||
[869ec42]: https://github.com/Gallopsled/pwntools/commit/869ec42082b4b98958dfe85103da9b101dde7daa
|
||||
[4893819]: https://github.com/Gallopsled/pwntools/commit/4893819b4c23182da570e2f4ea4c14d73af2c0df
|
||||
[2af55c9]: https://github.com/Gallopsled/pwntools/commit/2af55c9bc382eca23f89bc0abc7a07c075521f94
|
||||
|
||||
## 3.1.1
|
||||
|
||||
Fixed a bug in `MemLeak.struct` (PR: #768).
|
||||
|
||||
## 3.1.0
|
||||
|
||||
A number of smaller bugfixes and documentation tweaks.
|
||||
|
||||
## 3.0.4
|
||||
|
||||
- Fixed a bug that made 3.0.3 uninstallable (Issue: #751, PR: #752)
|
||||
|
||||
## 3.0.3 (September 18, 2016, broken release)
|
||||
## 3.0.3
|
||||
|
||||
- Fixed some performance and usability problems with the update system (Issues:
|
||||
#723, #724, #736. PRs: #729, #738, #747).
|
||||
- Fixed a bug related to internals in pyelftools (PRs: #730, #746).
|
||||
- Fixed an issue with travis (Issue: #741, PRs: #743, #744, #745).
|
||||
|
||||
## 3.0.2 (September 6, 2016)
|
||||
## 3.0.2
|
||||
|
||||
- Cherry-pick #695, as this was a regression-fix.
|
||||
- Added a fix for the update checker, as it would suggest prereleases as updates to stable releases.
|
||||
- Various documentation fixes.
|
||||
|
||||
## 3.0.1 (August 20, 2016)
|
||||
## 3.0.1
|
||||
|
||||
A small bugfix release. There were a lot of references to the `master`-branch, however after 3.0.0 we use the names `stable`, `beta` and `dev` for our branches.
|
||||
|
||||
## 3.0.0 (August 20, 2016)
|
||||
## 3.0.0
|
||||
|
||||
This was a large release (1305 commits since 2.2.0) with a lot of bugfixes and changes. The Binjitsu project, a fork of Pwntools, was merged back into Pwntools. As such, its features are now available here.
|
||||
|
||||
@@ -61,8 +372,8 @@ Android support via a new `adb` module, `context.device`, `context.adb_host`, an
|
||||
- Added `context.log_file` setting for sending logs to a file. This can be set with the `LOG_FILE` magic command-line option.
|
||||
- Added `context.noptrace` setting for disabling actions which require `ptrace` support. This is useful for turning all `gdb.debug` and `gdb.attach` options into no-ops, and can be set via the `NOPTRACE` magic command-line option.
|
||||
- Added `context.proxy` which hooks all connections and sends them to a SOCKS4/SOCKS5. This can be set via the `PROXY` magic command-line option.
|
||||
- Added `context.randomize` to control randommization of settings like XOR keys and register ordering (default off).
|
||||
- Added `context.termianl` for setting how to launch commands in a new terminal.
|
||||
- Added `context.randomize` to control randomization of settings like XOR keys and register ordering (default off).
|
||||
- Added `context.terminal` for setting how to launch commands in a new terminal.
|
||||
|
||||
#### DynELF and MemLeak Module
|
||||
|
||||
@@ -74,7 +385,7 @@ Android support via a new `adb` module, `context.device`, `context.adb_host`, an
|
||||
#### Encoders Module
|
||||
|
||||
- Added a `pwnlib.encoders` module for assembled-shellcode encoders/decoders
|
||||
- Includes position-indepentent basic XOR encoders
|
||||
- Includes position-independent basic XOR encoders
|
||||
- Includes position-independent delta encoders
|
||||
- Includes non-position-independent alphanumeric encoders for Intel
|
||||
- Includes position-independent alphanumeric encoders for ARM/Thumb
|
||||
@@ -125,7 +436,7 @@ Android support via a new `adb` module, `context.device`, `context.adb_host`, an
|
||||
- Added a multi-threaded `bruteforce()` implementation, `mbruteforce()`.
|
||||
- Added `dealarm_shell()` helper to remove the effects of `alarm()` after you've popped a shell.
|
||||
|
||||
## 2.2.0 (January 5, 2015)
|
||||
## 2.2.0
|
||||
|
||||
This was a large release with a lot of bugfixes and changes. Only the most significant
|
||||
are mentioned here.
|
||||
|
||||
+1
-1
@@ -2,6 +2,6 @@ graft examples
|
||||
graft extra
|
||||
include *.md *.txt *.sh *.yml MANIFEST.in
|
||||
recursive-include docs *.rst *.png Makefile *.py *.txt
|
||||
recursive-include pwnlib *.py *.asm *.rst *.md *.txt *.sh
|
||||
recursive-include pwnlib *.py *.asm *.rst *.md *.txt *.sh __doc__
|
||||
recursive-include pwn *.py *.asm *.rst *.md *.txt *.sh
|
||||
recursive-exclude *.pyc
|
||||
@@ -2,7 +2,7 @@
|
||||

|
||||
|
||||
[](https://docs.pwntools.com/)
|
||||
[](https://pypi.python.org/pypi/pwntools/)
|
||||
[](https://pypi.python.org/pypi/pwntools/)
|
||||
[](https://travis-ci.org/Gallopsled/pwntools)
|
||||
[](https://coveralls.io/github/Gallopsled/pwntools?branch=dev)
|
||||
[](https://twitter.com/pwntools)
|
||||
@@ -22,13 +22,10 @@ r.interactive()
|
||||
|
||||
# Try It Now!
|
||||
|
||||
You can now do a live demo of Pwntools, [right in your browser](http://demo.pwntools.com). Alternately, you can SSH to the same host, and log in as user `zerocool` with [this private key][key] (password `i_promise_not_to_be_evil`).
|
||||
|
||||
It will drop you into a clean, Docker-ized container. There is nothing of value on the VPS, so please don't be evil.
|
||||
|
||||
[key]: https://gist.githubusercontent.com/zachriggle/efa2e0080ae6de2e8344/raw/4b503e9db54f009d97477d03d4ba5678471f8ff0/id_rsa
|
||||
You can now do a live demo of Pwntools, [right in your browser](https://demo.pwntools.com).
|
||||
|
||||
# Documentation
|
||||
|
||||
Our documentation is available at [docs.pwntools.com](https://docs.pwntools.com/)
|
||||
|
||||
To get you started, we've provided some example solutions for past CTF challenges in our [write-ups repository](https://github.com/Gallopsled/pwntools-write-ups).
|
||||
@@ -41,13 +38,11 @@ Most of the functionality of pwntools is self-contained and Python-only. You sh
|
||||
|
||||
```sh
|
||||
apt-get update
|
||||
apt-get install python2.7 python-pip python-dev git libssl-dev
|
||||
apt-get install python2.7 python-pip python-dev git libssl-dev libffi-dev build-essential
|
||||
pip install --upgrade pip
|
||||
pip install --upgrade pwntools
|
||||
```
|
||||
|
||||
If you'd like to be an early tester of the the current beta release, add
|
||||
`--pre` to the command-line.
|
||||
|
||||
However, some of the features (assembling/disassembling foreign architectures) require non-Python dependencies. For more information, see the [complete installation instructions here](https://docs.pwntools.com/en/stable/install.html).
|
||||
|
||||
|
||||
|
||||
+5
-7
@@ -5,15 +5,13 @@ Pwntools makes extensive use of unit tests and integration tests to ensure every
|
||||
## Test Suite
|
||||
|
||||
|
||||
To run the test suite, it is beste to use Ubuntu 12.04 or 14.04, and run the following commands. **Be aware** that this will add a user to the machine, and create a public key for SSH login!
|
||||
To run the test suite, it is best to use Ubuntu 12.04 or 14.04, and run the following commands. **Be aware** that this will add a user to the machine, and create a public key for SSH login!
|
||||
|
||||
```sh
|
||||
bash .travis_install.sh
|
||||
bash .travis_ssh_setup.sh
|
||||
pip install -e .
|
||||
pip install -r docs/requirements.txt
|
||||
cd docs
|
||||
PWNLIB_NOTERM=1 make clean doctest
|
||||
bash travis/install.sh
|
||||
bash travis/ssh_setup.sh
|
||||
pip install --upgrade --editable .
|
||||
PWNLIB_NOTERM=1 make -C docs doctest
|
||||
```
|
||||
|
||||
## New Tests
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
sphinxcontrib-napoleon
|
||||
sphinxcontrib-autoprogram
|
||||
sphinxcontrib-autoprogram==0.1.2
|
||||
isort
|
||||
paramiko>=1.15.2
|
||||
mako>=1.0.0
|
||||
|
||||
+5
-1
@@ -1,9 +1,13 @@
|
||||
.. testsetup:: *
|
||||
|
||||
from pwn import *
|
||||
adb = pwnlib.adb
|
||||
|
||||
:mod:`pwnlib.adb` --- Android Debug Bridge
|
||||
=====================================================
|
||||
|
||||
.. automodule:: pwnlib.adb
|
||||
.. automodule:: pwnlib.adb.adb
|
||||
:members:
|
||||
|
||||
.. automodule:: pwnlib.adb.protocol
|
||||
:members:
|
||||
@@ -0,0 +1,9 @@
|
||||
.. testsetup:: *
|
||||
|
||||
from pwn import *
|
||||
|
||||
:mod:`pwnlib.args` --- Magic Command-Line Arguments
|
||||
=====================================================
|
||||
|
||||
.. automodule:: pwnlib.args
|
||||
:members:
|
||||
@@ -13,3 +13,13 @@
|
||||
|
||||
.. automodule:: pwnlib.asm
|
||||
:members:
|
||||
|
||||
Internal Functions
|
||||
=========================================
|
||||
|
||||
These are only included so that their tests are run.
|
||||
|
||||
You should never need these.
|
||||
|
||||
.. autofunction:: pwnlib.asm.dpkg_search_for_binutils
|
||||
.. autofunction:: pwnlib.asm.print_binutils_instructions
|
||||
@@ -14,45 +14,5 @@ pwntools comes with a handful of useful command-line utilities which serve as wr
|
||||
|
||||
.. toctree::
|
||||
|
||||
.. autoprogram:: pwnlib.commandline.asm:parser
|
||||
:prog: asm
|
||||
|
||||
.. autoprogram:: pwnlib.commandline.checksec:parser
|
||||
:prog: checksec
|
||||
|
||||
.. autoprogram:: pwnlib.commandline.constgrep:p
|
||||
:prog: constgrep
|
||||
|
||||
.. autoprogram:: pwnlib.commandline.cyclic:parser
|
||||
:prog: cyclic
|
||||
|
||||
.. autoprogram:: pwnlib.commandline.disasm:parser
|
||||
:prog: disasm
|
||||
|
||||
.. autoprogram:: pwnlib.commandline.elfdiff:p
|
||||
:prog: elfdiff
|
||||
|
||||
.. autoprogram:: pwnlib.commandline.elfpatch:p
|
||||
:prog: elfpatch
|
||||
|
||||
.. autoprogram:: pwnlib.commandline.errno:parser
|
||||
:prog: errno
|
||||
|
||||
.. autoprogram:: pwnlib.commandline.hex:parser
|
||||
:prog: hex
|
||||
|
||||
.. autoprogram:: pwnlib.commandline.phd:parser
|
||||
:prog: phd
|
||||
|
||||
.. autoprogram:: pwnlib.commandline.pwnstrip:p
|
||||
:prog: pwnstrip
|
||||
|
||||
.. autoprogram:: pwnlib.commandline.scramble:parser
|
||||
:prog: scramble
|
||||
|
||||
.. autoprogram:: pwnlib.commandline.shellcraft:p
|
||||
:prog: shellcraft
|
||||
|
||||
.. autoprogram:: pwnlib.commandline.unhex:parser
|
||||
:prog: unhex
|
||||
|
||||
.. autoprogram:: pwnlib.commandline.main:parser
|
||||
:prog: pwn
|
||||
+25
-3
@@ -44,6 +44,10 @@ extensions = [
|
||||
'sphinxcontrib.napoleon'
|
||||
]
|
||||
|
||||
# Napoleon settings
|
||||
napoleon_use_ivar = True
|
||||
napoleon_use_rtype = False
|
||||
|
||||
doctest_global_setup = '''
|
||||
import sys, os
|
||||
os.environ['PWNLIB_NOTERM'] = '1'
|
||||
@@ -52,17 +56,29 @@ import pwnlib
|
||||
pwnlib.context.context.reset_local()
|
||||
pwnlib.context.ContextType.defaults['log_level'] = 'ERROR'
|
||||
pwnlib.context.ContextType.defaults['randomize'] = False
|
||||
pwnlib.util.fiddling.default_style = {}
|
||||
pwnlib.term.text.when = 'never'
|
||||
pwnlib.log.install_default_handler()
|
||||
pwnlib.log.rootlogger.setLevel(1)
|
||||
|
||||
# Sphinx modifies sys.stdout, and context.log_terminal has
|
||||
# a reference to the original instance. We need to update
|
||||
# it for logging to be captured.
|
||||
class stdout(object):
|
||||
def __getattr__(self, name):
|
||||
return getattr(sys.stdout, name)
|
||||
def __setattr__(self, name, value):
|
||||
return setattr(sys.stdout, name, value)
|
||||
pwnlib.context.ContextType.defaults['log_console'] = stdout()
|
||||
'''
|
||||
|
||||
autodoc_member_order = 'alphabetical'
|
||||
autoclass_content = 'both'
|
||||
autodoc_member_order = 'groupwise' # 'alphabetical'
|
||||
|
||||
# Add any paths that contain templates here, relative to this directory.
|
||||
templates_path = ['_templates']
|
||||
|
||||
doctest_test_doctest_blocks = True
|
||||
doctest_test_doctest_blocks = 'true'
|
||||
|
||||
# The suffix of source filenames.
|
||||
source_suffix = '.rst'
|
||||
@@ -221,7 +237,7 @@ latex_documents = [
|
||||
]
|
||||
|
||||
intersphinx_mapping = {'python': ('https://docs.python.org/2.7', None),
|
||||
'paramiko': ('https://paramiko-docs.readthedocs.org/en/1.15/', None)}
|
||||
'paramiko': ('https://paramiko-docs.readthedocs.org/en/2.1/', None)}
|
||||
|
||||
# The name of an image file (relative to this directory) to place at the top of
|
||||
# the title page.
|
||||
@@ -337,3 +353,9 @@ if build_dash:
|
||||
html_theme_path = [sphinx_rtd_theme.get_html_theme_path()]
|
||||
|
||||
# otherwise, readthedocs.org uses their theme by default, so no need to specify it
|
||||
|
||||
|
||||
# -- Customization to Sphinx autodoc generation --------------------------------------------
|
||||
import sphinx.ext.autodoc
|
||||
|
||||
sphinx.ext.autodoc
|
||||
@@ -3,10 +3,32 @@
|
||||
from pwn import *
|
||||
import logging
|
||||
log = pwnlib.log.getLogger('pwnlib.context')
|
||||
context.clear()
|
||||
|
||||
:mod:`pwnlib.context` --- Setting runtime variables
|
||||
=====================================================
|
||||
|
||||
Many settings in ``pwntools`` are controlled via the global variable :data:`.context, such as the selected target operating system, architecture, and bit-width.
|
||||
|
||||
In general, exploits will start with something like:
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pwn import *
|
||||
context.arch = 'amd64'
|
||||
|
||||
Which sets up everything in the exploit for exploiting a 64-bit Intel binary.
|
||||
|
||||
The recommended method is to use ``context.binary`` to automagically set all of the appropriate values.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
from pwn import *
|
||||
context.binary = './challenge-binary'
|
||||
|
||||
Module Members
|
||||
=====================================================
|
||||
|
||||
.. autodata:: pwnlib.context.context
|
||||
|
||||
.. autoclass:: pwnlib.context.ContextType
|
||||
|
||||
+11
-3
@@ -3,8 +3,16 @@
|
||||
from pwnlib.elf import *
|
||||
from pwnlib.util.misc import which
|
||||
|
||||
:mod:`pwnlib.elf` --- Working with ELF binaries
|
||||
===============================================
|
||||
:mod:`pwnlib.elf` --- ELF Executables and Libraries
|
||||
===================================================
|
||||
|
||||
.. automodule:: pwnlib.elf
|
||||
:members:
|
||||
|
||||
|
||||
ELF Modules
|
||||
-------------------
|
||||
|
||||
.. toctree::
|
||||
elf/elf
|
||||
elf/config
|
||||
elf/corefile
|
||||
@@ -0,0 +1,10 @@
|
||||
.. testsetup:: *
|
||||
|
||||
from pwn import *
|
||||
from pwnlib.elf.config import parse_kconfig
|
||||
|
||||
:mod:`pwnlib.elf.config` --- Kernel Config Parsing
|
||||
===========================================================
|
||||
|
||||
.. automodule:: pwnlib.elf.config
|
||||
:members:
|
||||
@@ -0,0 +1,15 @@
|
||||
.. testsetup:: *
|
||||
|
||||
from pwn import *
|
||||
|
||||
:mod:`pwnlib.elf.corefile` --- Core Files
|
||||
===========================================================
|
||||
|
||||
.. automodule:: pwnlib.elf.corefile
|
||||
|
||||
.. autoclass:: pwnlib.elf.corefile.Corefile
|
||||
:members:
|
||||
:show-inheritance:
|
||||
|
||||
.. autoclass:: pwnlib.elf.corefile.Mapping
|
||||
:members:
|
||||
@@ -0,0 +1,27 @@
|
||||
.. testsetup:: *
|
||||
|
||||
from pwn import *
|
||||
|
||||
:mod:`pwnlib.elf.elf` --- ELF Files
|
||||
===========================================================
|
||||
|
||||
.. automodule:: pwnlib.elf.elf
|
||||
|
||||
.. autoclass:: pwnlib.elf.elf.ELF
|
||||
:members:
|
||||
:show-inheritance:
|
||||
:inherited-members:
|
||||
:exclude-members: address_offsets,
|
||||
get_data,
|
||||
get_dwarf_info,
|
||||
get_section,
|
||||
get_segment,
|
||||
has_dwarf_info,
|
||||
iter_sections,
|
||||
iter_segments
|
||||
|
||||
.. autoclass:: pwnlib.elf.elf.Function
|
||||
:members:
|
||||
|
||||
.. autoclass:: pwnlib.elf.elf.dotdict
|
||||
:members:
|
||||
@@ -0,0 +1,10 @@
|
||||
.. testsetup:: *
|
||||
|
||||
from pwn import *
|
||||
|
||||
|
||||
:mod:`pwnlib.flag` --- CTF Flag Management
|
||||
==========================================
|
||||
|
||||
.. automodule:: pwnlib.flag
|
||||
:members:
|
||||
@@ -1,3 +1,7 @@
|
||||
.. testsetup:: *
|
||||
|
||||
from pwn import *
|
||||
|
||||
:mod:`pwnlib.gdb` --- Working with GDB
|
||||
======================================
|
||||
|
||||
|
||||
@@ -13,11 +13,11 @@ Which imports a bazillion things into the global namespace to make your life eas
|
||||
|
||||
This is a quick list of most of the objects and routines imported, in rough order of importance and frequency of use.
|
||||
|
||||
- ``context``
|
||||
- :obj:`.context`
|
||||
- :data:`pwnlib.context.context`
|
||||
- Responsible for most of the pwntools convenience settings
|
||||
- Set `context.log_level = 'debug'` when troubleshooting your exploit
|
||||
- Scope-aware, so you can disable logging for a subsection of code via ``pwnlib.context.ContextType.local``
|
||||
- Scope-aware, so you can disable logging for a subsection of code via :meth:`.ContextType.local`
|
||||
- ``remote``, ``listen``, ``ssh``, ``process``
|
||||
- :mod:`pwnlib.tubes`
|
||||
- Super convenient wrappers around all of the common functionality for CTF challenges
|
||||
@@ -57,11 +57,11 @@ This is a quick list of most of the objects and routines imported, in rough orde
|
||||
- ``gdb.debug`` and ``gdb.attach``
|
||||
- :mod:`pwnlib.gdb`
|
||||
- Launch a binary under GDB and pop up a new terminal to interact with it. Automates setting breakpoints and makes iteration on exploits MUCH faster.
|
||||
- Alternately, attach to a running process given a PID, ``pwnlib.tubes`` object, or even just a socket that's connected to it
|
||||
- Alternately, attach to a running process given a PID, :mod:`pwnlib.tubes` object, or even just a socket that's connected to it
|
||||
- ``args``
|
||||
- Dictionary contining all-caps command-line arguments for quick access
|
||||
- Dictionary containing all-caps command-line arguments for quick access
|
||||
- Run via ``python foo.py REMOTE=1`` and ``args['REMOTE'] == '1'``.
|
||||
- Can also control logging verbosity and terminal fancyness
|
||||
- Can also control logging verbosity and terminal fanciness
|
||||
- `NOTERM`
|
||||
- `SILENT`
|
||||
- `DEBUG`
|
||||
@@ -78,7 +78,7 @@ This is a quick list of most of the objects and routines imported, in rough orde
|
||||
- It's the new ``getch``
|
||||
- ``safeeval``
|
||||
- :mod:`pwnlib.util.safeeval`
|
||||
- Functions for safely evalutaing python code without nasty side-effects.
|
||||
- Functions for safely evaluating python code without nasty side-effects.
|
||||
|
||||
These are all pretty self explanatory, but are useful to have in the global namespace.
|
||||
|
||||
|
||||
@@ -43,6 +43,7 @@ Each of the ``pwntools`` modules is documented here.
|
||||
:glob:
|
||||
|
||||
adb
|
||||
args
|
||||
asm
|
||||
atexception
|
||||
atexit
|
||||
@@ -52,10 +53,12 @@ Each of the ``pwntools`` modules is documented here.
|
||||
encoders
|
||||
elf
|
||||
exception
|
||||
flag
|
||||
fmtstr
|
||||
gdb
|
||||
log
|
||||
memleak
|
||||
protocols
|
||||
replacements
|
||||
rop
|
||||
rop/*
|
||||
@@ -67,6 +70,7 @@ Each of the ``pwntools`` modules is documented here.
|
||||
tubes
|
||||
tubes/*
|
||||
ui
|
||||
update
|
||||
useragents
|
||||
util/*
|
||||
|
||||
|
||||
+4
-11
@@ -24,17 +24,11 @@ pwntools is available as a ``pip`` package.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ apt-get install python2.7 python2.7-dev python-pip
|
||||
$ apt-get update
|
||||
$ apt-get install python2.7 python-pip python-dev git libssl-dev libffi-dev build-essential
|
||||
$ pip install --upgrade pip
|
||||
$ pip install --upgrade pwntools
|
||||
|
||||
Alternatively you can get early access to the beta release if you want to help
|
||||
file bugs or simple get newer features:
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ pip install --upgrade --pre pwntools
|
||||
|
||||
|
||||
Development
|
||||
--------------
|
||||
|
||||
@@ -43,7 +37,6 @@ If you are hacking on Pwntools locally, you'll want to do something like this:
|
||||
.. code-block:: bash
|
||||
|
||||
$ git clone https://github.com/Gallopsled/pwntools
|
||||
$ cd pwntools
|
||||
$ pip install -e .
|
||||
$ pip install --upgrade --editable ./pwntools
|
||||
|
||||
.. _Ubuntu: https://launchpad.net/~pwntools/+archive/ubuntu/binutils
|
||||
@@ -11,7 +11,10 @@ Building `binutils` from source takes about 60 seconds on a modern 8-core machin
|
||||
|
||||
Ubuntu
|
||||
^^^^^^^^^^^^^^^^
|
||||
First, add our `Personal Package Archive repository <http://binutils.pwntools.com>`__.
|
||||
|
||||
For Ubuntu 12.04 through 15.10, you must first add the pwntools `Personal Package Archive repository <http://binutils.pwntools.com>`__.
|
||||
|
||||
Ubuntu Xenial (16.04) has official packages for most architectures, and does not require this step.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
|
||||
@@ -176,8 +176,8 @@ loaded with useful time-saving shellcodes.
|
||||
Let's say that we want to `setreuid(getuid(), getuid())` followed by `dup`ing
|
||||
file descriptor 4 to `stdin`, `stdout`, and `stderr`, and then pop a shell!
|
||||
|
||||
>>> asm(shellcraft.setreuid() + shellcraft.dupsh(4)).encode('hex')
|
||||
'6a3158cd8089c36a465889d9cd806a045b6a0359496a3f58cd8075f86a68682f2f2f73682f62696e6a0b5889e331c999cd80'
|
||||
>>> asm(shellcraft.setreuid() + shellcraft.dupsh(4)).encode('hex') # doctest: +ELLIPSIS
|
||||
'6a3158cd80...'
|
||||
|
||||
|
||||
Misc Tools
|
||||
@@ -212,8 +212,8 @@ Stop hard-coding things! Look them up at runtime with :mod:`pwnlib.elf`.
|
||||
You can even patch and save the files.
|
||||
|
||||
>>> e = ELF('/bin/cat')
|
||||
>>> e.read(e.address+1, 3)
|
||||
'ELF'
|
||||
>>> e.read(e.address, 4)
|
||||
'\x7fELF'
|
||||
>>> e.asm(e.address, 'ret')
|
||||
>>> e.save('/tmp/quiet-cat')
|
||||
>>> disasm(file('/tmp/quiet-cat','rb').read(1))
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
:mod:`pwnlib.protocols` --- Wire Protocols
|
||||
=============================================
|
||||
|
||||
.. automodule:: pwnlib.protocols
|
||||
|
||||
|
||||
Supported Protocols
|
||||
-------------------
|
||||
|
||||
.. toctree::
|
||||
:maxdepth: 3
|
||||
:glob:
|
||||
|
||||
protocols/*
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
.. testsetup:: *
|
||||
|
||||
from pwn import *
|
||||
from pwnlib.protocols.adb import AdbClient
|
||||
|
||||
:mod:`pwnlib.protocols.adb` --- ADB Protocol Implementation
|
||||
===========================================================
|
||||
|
||||
.. automodule:: pwnlib.protocols.adb
|
||||
:members:
|
||||
@@ -0,0 +1,19 @@
|
||||
.. testsetup:: *
|
||||
|
||||
from pwn import *
|
||||
context.clear(arch='aarch64')
|
||||
|
||||
:mod:`pwnlib.shellcraft.aarch64` --- Shellcode for AArch64
|
||||
===========================================================
|
||||
|
||||
:mod:`pwnlib.shellcraft.aarch64`
|
||||
--------------------------------
|
||||
|
||||
.. automodule:: pwnlib.shellcraft.aarch64
|
||||
:members:
|
||||
|
||||
:mod:`pwnlib.shellcraft.aarch64.linux`
|
||||
--------------------------------------
|
||||
|
||||
.. automodule:: pwnlib.shellcraft.aarch64.linux
|
||||
:members:
|
||||
@@ -0,0 +1,19 @@
|
||||
.. testsetup:: *
|
||||
|
||||
from pwn import *
|
||||
context.clear(arch='mips')
|
||||
|
||||
:mod:`pwnlib.shellcraft.mips` --- Shellcode for MIPS
|
||||
===========================================================
|
||||
|
||||
:mod:`pwnlib.shellcraft.mips`
|
||||
-----------------------------
|
||||
|
||||
.. automodule:: pwnlib.shellcraft.mips
|
||||
:members:
|
||||
|
||||
:mod:`pwnlib.shellcraft.mips.linux`
|
||||
-----------------------------------
|
||||
|
||||
.. automodule:: pwnlib.shellcraft.mips.linux
|
||||
:members:
|
||||
@@ -27,4 +27,4 @@ Types of Tubes
|
||||
.. autoclass:: pwnlib.tubes.tube.tube()
|
||||
:members:
|
||||
:exclude-members: recv_raw, send_raw, settimeout_raw,
|
||||
can_recv_raw
|
||||
can_recv_raw, shutdown_raw, connected_raw,
|
||||
@@ -0,0 +1,10 @@
|
||||
.. testsetup:: *
|
||||
|
||||
from pwn import *
|
||||
from pwnlib.update import *
|
||||
|
||||
:mod:`pwnlib.update` --- Updating Pwntools
|
||||
===================================================
|
||||
|
||||
.. automodule:: pwnlib.update
|
||||
:members:
|
||||
@@ -1,6 +1,7 @@
|
||||
.. testsetup:: *
|
||||
|
||||
from pwnlib.util.fiddling import *
|
||||
from pwn import *
|
||||
from pwnlib.util.fiddling import *
|
||||
|
||||
|
||||
:mod:`pwnlib.util.fiddling` --- Utilities bit fiddling
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
.. testsetup:: *
|
||||
|
||||
from pwn import *
|
||||
test = pwnlib.util.sh_string.test
|
||||
|
||||
:mod:`pwnlib.util.sh_string` --- Shell Expansion is Hard
|
||||
===============================================================
|
||||
|
||||
.. automodule:: pwnlib.util.sh_string
|
||||
:members:
|
||||
@@ -0,0 +1,31 @@
|
||||
from pwn import *
|
||||
context.arch='aarch64'
|
||||
frame = SigreturnFrame()
|
||||
|
||||
registers = ['x%i' % i for i in range(0, 31)]
|
||||
registers += ['sp', 'pc']
|
||||
|
||||
|
||||
for index, register in enumerate(registers):
|
||||
setattr(frame, register, index)
|
||||
|
||||
assembly = '\n'.join([
|
||||
shellcraft.read(constants.STDIN_FILENO, 'sp', 1024),
|
||||
shellcraft.syscall(constants.SYS_rt_sigreturn)
|
||||
])
|
||||
|
||||
binary = ELF.from_assembly(assembly)
|
||||
|
||||
io = binary.process()
|
||||
io.flat(frame)
|
||||
io.wait()
|
||||
assert io.poll() == -11
|
||||
|
||||
corefile = io.corefile
|
||||
|
||||
for index, register in enumerate(registers):
|
||||
value = getattr(corefile, register)
|
||||
if index != value:
|
||||
log.error("%s != %i (%i)" % (register, index, value))
|
||||
else:
|
||||
log.success("%s == %i" % (register, value))
|
||||
@@ -0,0 +1,32 @@
|
||||
from pwn import *
|
||||
context.arch='amd64'
|
||||
frame = SigreturnFrame()
|
||||
|
||||
registers = ['rax', 'rbx', 'rcx', 'rdx',
|
||||
'rdi', 'rsi', 'rbp', 'rsp',
|
||||
'rip',
|
||||
'r8', 'r9', 'r10', 'r11', 'r12', 'r13', 'r14', 'r15']
|
||||
|
||||
for index, register in enumerate(registers):
|
||||
setattr(frame, register, index)
|
||||
|
||||
assembly = '\n'.join([
|
||||
shellcraft.read(constants.STDIN_FILENO, 'rsp', 1024),
|
||||
shellcraft.sigreturn()
|
||||
])
|
||||
|
||||
binary = ELF.from_assembly(assembly)
|
||||
|
||||
io = binary.process()
|
||||
io.flat(frame)
|
||||
io.wait()
|
||||
assert io.poll() == -11
|
||||
|
||||
corefile = io.corefile
|
||||
|
||||
for index, register in enumerate(registers):
|
||||
value = getattr(corefile, register)
|
||||
if index != value:
|
||||
log.error("%s != %i (%i)" % (register, index, value))
|
||||
else:
|
||||
log.success("%s == %i" % (register, value))
|
||||
@@ -0,0 +1,32 @@
|
||||
from pwn import *
|
||||
|
||||
context.arch='arm'
|
||||
frame = SigreturnFrame()
|
||||
|
||||
registers = ['r0', 'r1', 'r2', 'r3', 'r4', 'r5', 'r6', 'r7',
|
||||
'r8', 'r9', 'r10', 'fp', 'ip', 'sp', 'pc', 'lr']
|
||||
|
||||
|
||||
for index, register in enumerate(registers):
|
||||
setattr(frame, register, index)
|
||||
|
||||
assembly = '\n'.join([
|
||||
shellcraft.read(constants.STDIN_FILENO, 'sp', 1024),
|
||||
shellcraft.sigreturn()
|
||||
])
|
||||
|
||||
binary = ELF.from_assembly(assembly)
|
||||
|
||||
io = binary.process()
|
||||
io.flat(frame)
|
||||
io.wait()
|
||||
assert io.poll() == -11
|
||||
|
||||
corefile = io.corefile
|
||||
|
||||
for index, register in enumerate(registers):
|
||||
value = getattr(corefile, register)
|
||||
if index != value:
|
||||
log.error("%s != %i (%i)" % (register, index, value))
|
||||
else:
|
||||
log.success("%s == %i" % (register, value))
|
||||
@@ -0,0 +1,31 @@
|
||||
from pwn import *
|
||||
context.kernel='amd64'
|
||||
frame = SigreturnFrame()
|
||||
|
||||
registers = ['eax', 'ebx', 'ecx', 'edx',
|
||||
'edi', 'esi', 'ebp', 'esp',
|
||||
'eip']
|
||||
|
||||
for index, register in enumerate(registers):
|
||||
setattr(frame, register, index)
|
||||
|
||||
assembly = '\n'.join([
|
||||
shellcraft.read(constants.STDIN_FILENO, 'esp', 1024),
|
||||
shellcraft.sigreturn()
|
||||
])
|
||||
|
||||
binary = ELF.from_assembly(assembly)
|
||||
|
||||
io = binary.process()
|
||||
io.flat(frame)
|
||||
io.wait()
|
||||
assert io.poll() == -11
|
||||
|
||||
corefile = io.corefile
|
||||
|
||||
for index, register in enumerate(registers):
|
||||
value = getattr(corefile, register)
|
||||
if index != value:
|
||||
log.error("%s != %i (%i)" % (register, index, value))
|
||||
else:
|
||||
log.success("%s == %i" % (register, value))
|
||||
@@ -1,5 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
# cache list of shellcodes
|
||||
_shellcraft_shellcodes=$(shellcraft)
|
||||
_shellcraft_shellcodes=$(pwn shellcraft -l)
|
||||
|
||||
_shellcraft()
|
||||
{
|
||||
@@ -43,4 +44,5 @@ _shellcraft()
|
||||
COMPREPLY=( $(compgen -W "${_shellcraft_shellcodes}" -- ${cur}) )
|
||||
}
|
||||
|
||||
complete -F _shellcraft pwn shellcraft
|
||||
complete -F _shellcraft shellcraft
|
||||
@@ -1,58 +0,0 @@
|
||||
############################################################
|
||||
# Dockerfile to build Pwntools container
|
||||
# Based on Ubuntu
|
||||
############################################################
|
||||
|
||||
FROM ubuntu:trusty
|
||||
MAINTAINER Maintainer Gallopsled et al.
|
||||
|
||||
RUN apt-get update && apt-get install -y software-properties-common
|
||||
RUN apt-add-repository --yes ppa:pwntools/binutils
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y \
|
||||
binutils \
|
||||
binutils-aarch64-linux-gnu \
|
||||
binutils-arm-linux-gnueabihf \
|
||||
curl \
|
||||
gdb \
|
||||
gdbserver \
|
||||
gdb-multiarch \
|
||||
git \
|
||||
libc6-i386 \
|
||||
libc6-arm64-cross \
|
||||
libc6-armhf-cross \
|
||||
libc6-dev-i386 \
|
||||
libffi-dev \
|
||||
libglib2.0-dev \
|
||||
libncurses5-dev \
|
||||
libncursesw5-dev \
|
||||
ltrace \
|
||||
python-dev \
|
||||
python-pip \
|
||||
python3-pip \
|
||||
python2.7 \
|
||||
qemu \
|
||||
qemu-user-static \
|
||||
strace \
|
||||
tmux \
|
||||
wget
|
||||
RUN pip install --upgrade ipython
|
||||
RUN useradd -m zerocool
|
||||
RUN usermod -U zerocool
|
||||
|
||||
RUN mkdir -p /etc/qemu-binfmt
|
||||
RUN ln -s /usr/aarch64-linux-gnu /etc/qemu-binfmt/aarch64
|
||||
RUN ln -s /usr/arm-linux-gnueabihf /etc/qemu-binfmt/arm
|
||||
|
||||
RUN pip install --upgrade pip pycparser psutil python-ptrace
|
||||
RUN pip3 install --upgrade pip pycparser psutil python-ptrace
|
||||
|
||||
RUN pip install --upgrade git+https://github.com/Gallopsled/pwntools.git
|
||||
|
||||
RUN locale-gen en_US.UTF-8
|
||||
ENV LANG en_US.UTF-8
|
||||
ENV LANGUAGE en_US:en
|
||||
ENV LC_ALL en_US.UTF-8
|
||||
|
||||
RUN chown -R zerocool.zerocool /home/zerocool
|
||||
RUN chsh -s /bin/bash zerocool
|
||||
@@ -0,0 +1,13 @@
|
||||
subdirs=xenial stable $(wildcard */)
|
||||
makefiles=$(wildcard */Makefile)
|
||||
tags=stable beta dev
|
||||
|
||||
all: $(makefiles) $(subdirs)
|
||||
|
||||
$(subdirs):
|
||||
docker build -t pwntools/pwntools:$(shell basename $(@)) "$@"
|
||||
|
||||
$(makefiles):
|
||||
make -C $(shell dirname $@)
|
||||
|
||||
.PHONY: all $(subdirs) $(makefiles)
|
||||
@@ -0,0 +1,6 @@
|
||||
FROM pwntools/pwntools:stable
|
||||
|
||||
USER root
|
||||
RUN pip install --upgrade git+https://github.com/Gallopsled/pwntools@beta
|
||||
RUN PWNLIB_NOTERM=1 pwn update
|
||||
USER pwntools
|
||||
@@ -0,0 +1,6 @@
|
||||
FROM pwntools/pwntools:stable
|
||||
|
||||
USER root
|
||||
RUN pip install --upgrade git+https://github.com/Gallopsled/pwntools@dev
|
||||
RUN PWNLIB_NOTERM=1 pwn update
|
||||
USER pwntools
|
||||
@@ -0,0 +1,26 @@
|
||||
############################################################
|
||||
# Dockerfile to build Pwntools container
|
||||
# Based on Ubuntu
|
||||
############################################################
|
||||
|
||||
FROM kalilinux/kali-linux-docker
|
||||
MAINTAINER Maintainer Gallopsled et al.
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y build-essential
|
||||
RUN apt-get install -y git
|
||||
RUN apt-get install -y libssl-dev
|
||||
RUN apt-get install -y libffi-dev
|
||||
RUN apt-get install -y python2.7
|
||||
RUN apt-get install -y python-pip
|
||||
RUN apt-get install -y python-dev
|
||||
RUN pip install --upgrade pip
|
||||
RUN python -m pip install --upgrade pwntools
|
||||
RUN PWNLIB_NOTERM=1 pwn update
|
||||
|
||||
RUN apt-get install -y sudo
|
||||
RUN useradd -m pwntools
|
||||
RUN passwd --delete --unlock pwntools
|
||||
RUN echo "pwntools ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/pwntools
|
||||
USER pwntools
|
||||
WORKDIR /home/pwntools
|
||||
@@ -0,0 +1,8 @@
|
||||
all: Dockerfile
|
||||
|
||||
Dockerfile: ../stable/Dockerfile FORCE
|
||||
sed "s|ubuntu:xenial|kalilinux/kali-linux-docker|" < "$<" > "$@"
|
||||
|
||||
FORCE:
|
||||
|
||||
.PHONY: all
|
||||
@@ -0,0 +1,26 @@
|
||||
############################################################
|
||||
# Dockerfile to build Pwntools container
|
||||
# Based on Ubuntu
|
||||
############################################################
|
||||
|
||||
FROM ubuntu:precise
|
||||
MAINTAINER Maintainer Gallopsled et al.
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y build-essential
|
||||
RUN apt-get install -y git
|
||||
RUN apt-get install -y libssl-dev
|
||||
RUN apt-get install -y libffi-dev
|
||||
RUN apt-get install -y python2.7
|
||||
RUN apt-get install -y python-pip
|
||||
RUN apt-get install -y python-dev
|
||||
RUN pip install --upgrade pip
|
||||
RUN python -m pip install --upgrade pwntools
|
||||
RUN PWNLIB_NOTERM=1 pwn update
|
||||
|
||||
RUN apt-get install -y sudo
|
||||
RUN useradd -m pwntools
|
||||
RUN passwd --delete --unlock pwntools
|
||||
RUN echo "pwntools ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/pwntools
|
||||
USER pwntools
|
||||
WORKDIR /home/pwntools
|
||||
@@ -0,0 +1,8 @@
|
||||
all: Dockerfile
|
||||
|
||||
Dockerfile: ../xenial/Dockerfile FORCE
|
||||
sed "s|ubuntu:xenial|ubuntu:precise|" < "$<" > "$@"
|
||||
|
||||
FORCE:
|
||||
|
||||
.PHONY: all
|
||||
@@ -0,0 +1,26 @@
|
||||
############################################################
|
||||
# Dockerfile to build Pwntools container
|
||||
# Based on Ubuntu
|
||||
############################################################
|
||||
|
||||
FROM ubuntu:xenial
|
||||
MAINTAINER Maintainer Gallopsled et al.
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y build-essential
|
||||
RUN apt-get install -y git
|
||||
RUN apt-get install -y libssl-dev
|
||||
RUN apt-get install -y libffi-dev
|
||||
RUN apt-get install -y python2.7
|
||||
RUN apt-get install -y python-pip
|
||||
RUN apt-get install -y python-dev
|
||||
RUN pip install --upgrade pip
|
||||
RUN python -m pip install --upgrade pwntools
|
||||
RUN PWNLIB_NOTERM=1 pwn update
|
||||
|
||||
RUN apt-get install -y sudo
|
||||
RUN useradd -m pwntools
|
||||
RUN passwd --delete --unlock pwntools
|
||||
RUN echo "pwntools ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/pwntools
|
||||
USER pwntools
|
||||
WORKDIR /home/pwntools
|
||||
@@ -0,0 +1,8 @@
|
||||
all: Dockerfile
|
||||
|
||||
Dockerfile: ../xenial/Dockerfile FORCE
|
||||
cp "$<" "$@"
|
||||
|
||||
FORCE:
|
||||
|
||||
.PHONY: all
|
||||
@@ -0,0 +1,26 @@
|
||||
############################################################
|
||||
# Dockerfile to build Pwntools container
|
||||
# Based on Ubuntu
|
||||
############################################################
|
||||
|
||||
FROM ubuntu:trusty
|
||||
MAINTAINER Maintainer Gallopsled et al.
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y build-essential
|
||||
RUN apt-get install -y git
|
||||
RUN apt-get install -y libssl-dev
|
||||
RUN apt-get install -y libffi-dev
|
||||
RUN apt-get install -y python2.7
|
||||
RUN apt-get install -y python-pip
|
||||
RUN apt-get install -y python-dev
|
||||
RUN pip install --upgrade pip
|
||||
RUN python -m pip install --upgrade pwntools
|
||||
RUN PWNLIB_NOTERM=1 pwn update
|
||||
|
||||
RUN apt-get install -y sudo
|
||||
RUN useradd -m pwntools
|
||||
RUN passwd --delete --unlock pwntools
|
||||
RUN echo "pwntools ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/pwntools
|
||||
USER pwntools
|
||||
WORKDIR /home/pwntools
|
||||
@@ -0,0 +1,8 @@
|
||||
all: Dockerfile
|
||||
|
||||
Dockerfile: ../xenial/Dockerfile FORCE
|
||||
sed "s|ubuntu:xenial|ubuntu:trusty|" < "$<" > "$@"
|
||||
|
||||
FORCE:
|
||||
|
||||
.PHONY: all
|
||||
@@ -0,0 +1,26 @@
|
||||
############################################################
|
||||
# Dockerfile to build Pwntools container
|
||||
# Based on Ubuntu
|
||||
############################################################
|
||||
|
||||
FROM ubuntu:xenial
|
||||
MAINTAINER Maintainer Gallopsled et al.
|
||||
|
||||
RUN apt-get update
|
||||
RUN apt-get install -y build-essential
|
||||
RUN apt-get install -y git
|
||||
RUN apt-get install -y libssl-dev
|
||||
RUN apt-get install -y libffi-dev
|
||||
RUN apt-get install -y python2.7
|
||||
RUN apt-get install -y python-pip
|
||||
RUN apt-get install -y python-dev
|
||||
RUN pip install --upgrade pip
|
||||
RUN python -m pip install --upgrade pwntools
|
||||
RUN PWNLIB_NOTERM=1 pwn update
|
||||
|
||||
RUN apt-get install -y sudo
|
||||
RUN useradd -m pwntools
|
||||
RUN passwd --delete --unlock pwntools
|
||||
RUN echo "pwntools ALL=(ALL:ALL) NOPASSWD: ALL" > /etc/sudoers.d/pwntools
|
||||
USER pwntools
|
||||
WORKDIR /home/pwntools
|
||||
+5
-2
@@ -1,5 +1,7 @@
|
||||
# Promote useful stuff to toplevel
|
||||
from .toplevel import *
|
||||
from __future__ import absolute_import
|
||||
|
||||
from pwn.toplevel import *
|
||||
|
||||
pwnlib.args.initialize()
|
||||
pwnlib.log.install_default_handler()
|
||||
@@ -13,4 +15,5 @@ if not platform.architecture()[0].startswith('64'):
|
||||
See Gallopsled/pwntools#518 for more information."""
|
||||
log.warn_once('Pwntools does not support 32-bit Python. Use a 64-bit release.')
|
||||
|
||||
pwnlib.update.check_automatically()
|
||||
with context.local(log_console=sys.stderr):
|
||||
pwnlib.update.check_automatically()
|
||||
+12
-6
@@ -6,6 +6,7 @@ import operator
|
||||
import os
|
||||
import re
|
||||
import socks
|
||||
import signal
|
||||
import string
|
||||
import struct
|
||||
import subprocess
|
||||
@@ -14,6 +15,8 @@ import tempfile
|
||||
import threading
|
||||
import time
|
||||
|
||||
from pprint import pprint
|
||||
|
||||
import pwnlib
|
||||
from pwnlib import *
|
||||
from pwnlib.asm import *
|
||||
@@ -21,14 +24,15 @@ from pwnlib.context import Thread
|
||||
from pwnlib.context import context
|
||||
from pwnlib.dynelf import DynELF
|
||||
from pwnlib.encoders import *
|
||||
from pwnlib.elf import Core
|
||||
from pwnlib.elf import ELF
|
||||
from pwnlib.elf import load
|
||||
from pwnlib.elf.corefile import Core, Corefile, Coredump
|
||||
from pwnlib.elf.elf import ELF, load
|
||||
from pwnlib.encoders import *
|
||||
from pwnlib.exception import PwnlibException
|
||||
from pwnlib.gdb import attach, debug, debug_assembly, debug_shellcode
|
||||
from pwnlib.flag import *
|
||||
from pwnlib.fmtstr import FmtStr, fmtstr_payload
|
||||
from pwnlib.log import getLogger
|
||||
from pwnlib.memleak import MemLeak
|
||||
from pwnlib.memleak import MemLeak, RelativeMemLeak
|
||||
from pwnlib.regsort import *
|
||||
from pwnlib.replacements import *
|
||||
from pwnlib.rop import ROP
|
||||
@@ -36,8 +40,8 @@ from pwnlib.rop.srop import SigreturnFrame
|
||||
from pwnlib.runner import *
|
||||
from pwnlib.timeout import Timeout
|
||||
from pwnlib.tubes.listen import listen
|
||||
from pwnlib.tubes.process import process
|
||||
from pwnlib.tubes.remote import remote, tcp, udp
|
||||
from pwnlib.tubes.process import process, PTY, PIPE, STDOUT
|
||||
from pwnlib.tubes.remote import remote, tcp, udp, connect
|
||||
from pwnlib.tubes.serialtube import serialtube
|
||||
from pwnlib.tubes.ssh import ssh
|
||||
from pwnlib.tubes.tube import tube
|
||||
@@ -47,6 +51,7 @@ from pwnlib.util import iters
|
||||
from pwnlib.util import net
|
||||
from pwnlib.util import proc
|
||||
from pwnlib.util import safeeval
|
||||
from pwnlib.util.crc import BitPolynom
|
||||
from pwnlib.util.cyclic import *
|
||||
from pwnlib.util.fiddling import *
|
||||
from pwnlib.util.getdents import *
|
||||
@@ -55,6 +60,7 @@ from pwnlib.util.lists import *
|
||||
from pwnlib.util.misc import *
|
||||
from pwnlib.util.packing import *
|
||||
from pwnlib.util.proc import pidof
|
||||
from pwnlib.util.sh_string import sh_string, sh_prepare, sh_command_with
|
||||
from pwnlib.util.splash import *
|
||||
from pwnlib.util.web import *
|
||||
|
||||
|
||||
+3
-1
@@ -1,6 +1,8 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import importlib
|
||||
|
||||
from .version import __version__
|
||||
from pwnlib.version import __version__
|
||||
|
||||
version = __version__
|
||||
|
||||
|
||||
+49
-24
@@ -1,6 +1,8 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from .context import LocalContext
|
||||
from .context import context
|
||||
from __future__ import absolute_import
|
||||
|
||||
from pwnlib.context import LocalContext
|
||||
from pwnlib.context import context
|
||||
|
||||
|
||||
class ABI(object):
|
||||
@@ -24,7 +26,8 @@ class ABI(object):
|
||||
#: Indicates that this ABI returns to the next address on the slot
|
||||
returns = True
|
||||
|
||||
def __init__(self, regs, align, minimum):
|
||||
def __init__(self, stack, regs, align, minimum):
|
||||
self.stack = stack
|
||||
self.register_arguments = regs
|
||||
self.arg_alignment = align
|
||||
self.stack_minimum = minimum
|
||||
@@ -32,35 +35,52 @@ class ABI(object):
|
||||
@staticmethod
|
||||
@LocalContext
|
||||
def default():
|
||||
if context.os == 'android':
|
||||
context.os = 'linux'
|
||||
|
||||
return {
|
||||
(32, 'i386', 'linux'): linux_i386,
|
||||
(64, 'aarch64', 'linux'): linux_aarch64,
|
||||
(64, 'amd64', 'linux'): linux_amd64,
|
||||
(32, 'arm', 'linux'): linux_arm,
|
||||
(32, 'thumb', 'linux'): linux_arm,
|
||||
(32, 'mips', 'linux'): linux_mips,
|
||||
(32, 'i386', 'windows'): windows_i386,
|
||||
(64, 'amd64', 'windows'): windows_amd64,
|
||||
(32, 'powerpc', 'linux'): linux_ppc,
|
||||
(64, 'powerpc', 'linux'): linux_ppc64,
|
||||
}[(context.bits, context.arch, context.os)]
|
||||
|
||||
@staticmethod
|
||||
@LocalContext
|
||||
def syscall():
|
||||
if context.os == 'android':
|
||||
context.os = 'linux'
|
||||
|
||||
return {
|
||||
(32, 'i386', 'linux'): linux_i386_syscall,
|
||||
(64, 'amd64', 'linux'): linux_amd64_syscall,
|
||||
(64, 'aarch64', 'linux'): linux_aarch64_syscall,
|
||||
(32, 'arm', 'linux'): linux_arm_syscall,
|
||||
(32, 'thumb', 'linux'): linux_arm_syscall,
|
||||
(32, 'mips', 'linux'): linux_mips_syscall,
|
||||
(64, 'aarch64', 'linux'): linux_aarch64_syscall,
|
||||
(32, 'powerpc', 'linux'): linux_ppc_syscall,
|
||||
(64, 'powerpc', 'linux'): linux_ppc64_syscall,
|
||||
}[(context.bits, context.arch, context.os)]
|
||||
|
||||
@staticmethod
|
||||
@LocalContext
|
||||
def sigreturn():
|
||||
if context.os == 'android':
|
||||
context.os = 'linux'
|
||||
|
||||
return {
|
||||
(32, 'i386', 'linux'): linux_i386_sigreturn,
|
||||
(64, 'amd64', 'linux'): linux_amd64_sigreturn,
|
||||
(32, 'arm', 'linux'): linux_arm_sigreturn,
|
||||
(32, 'thumb', 'linux'): linux_arm_sigreturn,
|
||||
(64, 'aarch64', 'linux'): linux_aarch64_sigreturn,
|
||||
}[(context.bits, context.arch, context.os)]
|
||||
|
||||
class SyscallABI(ABI):
|
||||
@@ -68,9 +88,9 @@ class SyscallABI(ABI):
|
||||
The syscall ABI treats the syscall number as the zeroth argument,
|
||||
which must be loaded into the specified register.
|
||||
"""
|
||||
def __init__(self, register_arguments, *a, **kw):
|
||||
super(SyscallABI, self).__init__(register_arguments, *a, **kw)
|
||||
self.syscall_register = register_arguments[0]
|
||||
def __init__(self, *a, **kw):
|
||||
super(SyscallABI, self).__init__(*a, **kw)
|
||||
self.syscall_register = self.register_arguments[0]
|
||||
|
||||
class SigreturnABI(SyscallABI):
|
||||
"""
|
||||
@@ -81,26 +101,31 @@ class SigreturnABI(SyscallABI):
|
||||
returns = False
|
||||
|
||||
|
||||
linux_i386 = ABI([], 4, 0)
|
||||
linux_amd64 = ABI(['rdi','rsi','rdx','rcx','r8','r9'], 8, 0)
|
||||
linux_arm = ABI(['r0', 'r1', 'r2', 'r3'], 8, 0)
|
||||
linux_aarch64 = ABI(['x0', 'x1', 'x2', 'x3'], 16, 0)
|
||||
linux_mips = ABI(['$a0','$a1','$a2','$a3'], 4, 0)
|
||||
linux_i386 = ABI('esp', [], 4, 0)
|
||||
linux_amd64 = ABI('rsp', ['rdi','rsi','rdx','rcx','r8','r9'], 8, 0)
|
||||
linux_arm = ABI('sp', ['r0', 'r1', 'r2', 'r3'], 8, 0)
|
||||
linux_aarch64 = ABI('sp', ['x0', 'x1', 'x2', 'x3'], 16, 0)
|
||||
linux_mips = ABI('$sp', ['$a0','$a1','$a2','$a3'], 4, 0)
|
||||
linux_ppc = ABI('sp', ['r3', 'r4', 'r5', 'r6', 'r7', 'r8', 'r9', 'r10'], 4, 0)
|
||||
linux_ppc64 = ABI('sp', ['r3', 'r4', 'r5', 'r6', 'r7', 'r8', 'r9', 'r10'], 8, 0)
|
||||
|
||||
linux_i386_syscall = SyscallABI(['eax', 'ebx', 'ecx', 'edx', 'esi', 'edi', 'ebp'], 4, 0)
|
||||
linux_amd64_syscall = SyscallABI(['rax','rdi', 'rsi', 'rdx', 'r10', 'r8', 'r9'], 8, 0)
|
||||
linux_arm_syscall = SyscallABI(['r7', 'r0', 'r1', 'r2', 'r3', 'r4', 'r5', 'r6'], 4, 0)
|
||||
linux_aarch64_syscall = SyscallABI(['x8', 'x0', 'x1', 'x2', 'x3', 'x4', 'x5', 'x6'], 16, 0)
|
||||
linux_mips_syscall = ABI(['$v0', '$a0','$a1','$a2','$a3'], 4, 0)
|
||||
linux_i386_syscall = SyscallABI('esp', ['eax', 'ebx', 'ecx', 'edx', 'esi', 'edi', 'ebp'], 4, 0)
|
||||
linux_amd64_syscall = SyscallABI('rsp', ['rax', 'rdi', 'rsi', 'rdx', 'r10', 'r8', 'r9'], 8, 0)
|
||||
linux_arm_syscall = SyscallABI('sp', ['r7', 'r0', 'r1', 'r2', 'r3', 'r4', 'r5', 'r6'], 4, 0)
|
||||
linux_aarch64_syscall = SyscallABI('sp', ['x8', 'x0', 'x1', 'x2', 'x3', 'x4', 'x5', 'x6'], 16, 0)
|
||||
linux_mips_syscall = SyscallABI('$sp', ['$v0','$a0','$a1','$a2','$a3'], 4, 0)
|
||||
linux_ppc_syscall = ABI('sp', ['r0', 'r3', 'r4', 'r5', 'r6', 'r7', 'r8', 'r9'], 4, 0)
|
||||
linux_ppc64_syscall = ABI('sp', ['r0', 'r3', 'r4', 'r5', 'r6', 'r7', 'r8', 'r9'], 8, 0)
|
||||
|
||||
linux_i386_sigreturn = SigreturnABI(['eax'], 4, 0)
|
||||
linux_amd64_sigreturn = SigreturnABI(['rax'], 4, 0)
|
||||
linux_arm_sigreturn = SigreturnABI(['r7'], 4, 0)
|
||||
linux_i386_sigreturn = SigreturnABI('esp', ['eax'], 4, 0)
|
||||
linux_amd64_sigreturn = SigreturnABI('rsp', ['rax'], 4, 0)
|
||||
linux_arm_sigreturn = SigreturnABI('sp', ['r7'], 4, 0)
|
||||
linux_aarch64_sigreturn = SigreturnABI('sp', ['x8'], 16, 0)
|
||||
|
||||
windows_i386 = ABI([], 4, 0)
|
||||
windows_amd64 = ABI(['rcx','rdx','r8','r9'], 32, 32)
|
||||
windows_i386 = ABI('esp', [], 4, 0)
|
||||
windows_amd64 = ABI('rsp', ['rcx','rdx','r8','r9'], 32, 32)
|
||||
|
||||
# Fake ABIs used by SROP
|
||||
linux_i386_srop = ABI(['eax'], 4, 0)
|
||||
linux_amd64_srop = ABI(['rax'], 4, 0)
|
||||
linux_arm_srop = ABI(['r7'], 4, 0)
|
||||
linux_i386_srop = ABI('esp', ['eax'], 4, 0)
|
||||
linux_amd64_srop = ABI('rsp', ['rax'], 4, 0)
|
||||
linux_arm_srop = ABI('sp', ['r7'], 4, 0)
|
||||
-723
@@ -1,723 +0,0 @@
|
||||
"""Provides utilities for interacting with Android devices via the Android Debug Bridge.
|
||||
"""
|
||||
import glob
|
||||
import os
|
||||
import platform
|
||||
import re
|
||||
import shutil
|
||||
import tempfile
|
||||
import time
|
||||
|
||||
import dateutil.parser
|
||||
|
||||
from . import atexit
|
||||
from . import tubes
|
||||
from .context import context
|
||||
from .context import LocalContext
|
||||
from .device import Device
|
||||
from .log import getLogger
|
||||
from .util import misc
|
||||
|
||||
log = getLogger(__name__)
|
||||
|
||||
def adb(argv, *a, **kw):
|
||||
"""Returns the output of an ADB subcommand."""
|
||||
if isinstance(argv, (str, unicode)):
|
||||
argv = [argv]
|
||||
|
||||
log.debug("$ " + ' '.join(context.adb + argv))
|
||||
|
||||
return tubes.process.process(context.adb + argv, *a, **kw).recvall()
|
||||
|
||||
def root():
|
||||
"""Restarts adbd as root."""
|
||||
log.info("Enabling root on %s" % context.device)
|
||||
|
||||
with context.quiet:
|
||||
reply = adb('root')
|
||||
|
||||
if 'already running as root' in reply:
|
||||
return
|
||||
|
||||
elif not reply or 'restarting adbd as root' in reply:
|
||||
with context.quiet:
|
||||
wait_for_device()
|
||||
|
||||
else:
|
||||
log.error("Could not run as root:\n%s" % reply)
|
||||
|
||||
|
||||
def reboot(wait=True):
|
||||
"""Reboots the device."""
|
||||
log.info('Rebooting device %s' % context.device)
|
||||
|
||||
with context.quiet:
|
||||
adb('reboot')
|
||||
|
||||
if wait:
|
||||
wait_for_device()
|
||||
|
||||
def reboot_bootloader():
|
||||
"""Reboots the device to the bootloader."""
|
||||
log.info('Rebooting %s to bootloader' % context.device)
|
||||
|
||||
with context.quiet:
|
||||
adb('reboot-bootloader')
|
||||
|
||||
class AdbDevice(Device):
|
||||
"""Encapsulates information about a connected device."""
|
||||
def __init__(self, serial, type, port, product='unknown', model='unknown', device='unknown'):
|
||||
self.serial = serial
|
||||
self.type = type
|
||||
self.port = port
|
||||
self.product = product
|
||||
self.model = model.replace('_', ' ')
|
||||
self.device = device
|
||||
|
||||
if product == 'unknown':
|
||||
return
|
||||
|
||||
with context.local(device=serial):
|
||||
abi = str(properties.ro.product.cpu.abi)
|
||||
context.clear()
|
||||
context.arch = str(abi)
|
||||
self.arch = context.arch
|
||||
self.bits = context.bits
|
||||
self.endian = context.endian
|
||||
|
||||
def __str__(self):
|
||||
return self.serial
|
||||
|
||||
def __repr__(self):
|
||||
fields = ['serial', 'type', 'port', 'product', 'model', 'device']
|
||||
return '%s(%s)' % (self.__class__.__name__,
|
||||
', '.join(('%s=%r' % (field, getattr(self, field)) for field in fields)))
|
||||
|
||||
@staticmethod
|
||||
def from_adb_output(line):
|
||||
fields = line.split()
|
||||
|
||||
"""
|
||||
Example output:
|
||||
ZX1G22LM7G device usb:336789504X product:shamu model:Nexus_6 device:shamu features:cmd,shell_v2
|
||||
84B5T15A29020449 device usb:336855040X product:angler model:Nexus_6P device:angler
|
||||
0062741b0e54b353 unauthorized usb:337641472X
|
||||
"""
|
||||
|
||||
# The last few fields need to be split at colons.
|
||||
split = lambda x: x.split(':')[-1]
|
||||
fields[3:] = list(map(split, fields[3:]))
|
||||
|
||||
return AdbDevice(*fields[:6])
|
||||
|
||||
@context.quiet
|
||||
def devices(serial=None):
|
||||
"""Returns a list of ``Device`` objects corresponding to the connected devices."""
|
||||
lines = adb(['devices', '-l'])
|
||||
result = []
|
||||
|
||||
for line in lines.splitlines():
|
||||
# Skip the first 'List of devices attached' line, and the final empty line.
|
||||
if 'List of devices' in line or not line.strip():
|
||||
continue
|
||||
device = AdbDevice.from_adb_output(line)
|
||||
if device.serial == serial:
|
||||
return device
|
||||
result.append(device)
|
||||
|
||||
return tuple(result)
|
||||
|
||||
@LocalContext
|
||||
def wait_for_device(kick=False):
|
||||
"""Waits for a device to be connected."""
|
||||
with log.waitfor("Waiting for device to come online") as w:
|
||||
with context.quiet:
|
||||
if kick:
|
||||
try:
|
||||
adb(['reconnect'])
|
||||
except Exception:
|
||||
pass
|
||||
adb('wait-for-device')
|
||||
|
||||
for device in devices():
|
||||
if context.device == device:
|
||||
return device
|
||||
break
|
||||
else:
|
||||
log.error("Could not find any devices")
|
||||
|
||||
with context.local(device=device):
|
||||
# There may be multiple devices, so context.device is
|
||||
# insufficient. Pick the first device reported.
|
||||
w.success('%s (%s %s %s)' % (device,
|
||||
product(),
|
||||
build(),
|
||||
_build_date()))
|
||||
|
||||
return context.device
|
||||
|
||||
def disable_verity():
|
||||
"""Disables dm-verity on the device."""
|
||||
with log.waitfor("Disabling dm-verity on %s" % context.device) as w:
|
||||
root()
|
||||
|
||||
with context.quiet:
|
||||
reply = adb('disable-verity')
|
||||
|
||||
if 'Verity already disabled' in reply:
|
||||
return
|
||||
elif 'Now reboot your device' in reply:
|
||||
reboot(wait=True)
|
||||
else:
|
||||
log.error("Could not disable verity:\n%s" % reply)
|
||||
|
||||
|
||||
def remount():
|
||||
"""Remounts the filesystem as writable."""
|
||||
with log.waitfor("Remounting filesystem on %s" % context.device) as w:
|
||||
disable_verity()
|
||||
root()
|
||||
|
||||
with context.quiet:
|
||||
reply = adb('remount')
|
||||
|
||||
if 'remount succeeded' not in reply:
|
||||
log.error("Could not remount filesystem:\n%s" % reply)
|
||||
|
||||
def unroot():
|
||||
"""Restarts adbd as AID_SHELL."""
|
||||
log.info("Unrooting %s" % context.device)
|
||||
with context.quiet:
|
||||
reply = adb('unroot')
|
||||
|
||||
if 'restarting adbd as non root' not in reply:
|
||||
log.error("Could not run as root:\n%s" % reply)
|
||||
|
||||
def pull(remote_path, local_path=None):
|
||||
"""Download a file from the device.
|
||||
|
||||
Arguments:
|
||||
remote_path(str): Path or directory of the file on the device.
|
||||
local_path(str): Path to save the file to.
|
||||
Uses the file's name by default.
|
||||
"""
|
||||
if local_path is None:
|
||||
local_path = os.path.basename(remote_path)
|
||||
|
||||
msg = "Pulling %r from %r" % (remote_path, local_path)
|
||||
|
||||
if context.log_level == 'debug':
|
||||
msg += ' (%s)' % context.device
|
||||
|
||||
result = ''
|
||||
with log.waitfor(msg) as w:
|
||||
with context.quiet:
|
||||
args = context.adb + ['pull', remote_path, local_path]
|
||||
io = tubes.process.process(args)
|
||||
result = io.recvall()
|
||||
|
||||
if 0 != io.poll(block=True):
|
||||
log.error(result)
|
||||
|
||||
return result
|
||||
|
||||
def push(local_path, remote_path):
|
||||
"""Upload a file to the device.
|
||||
|
||||
Arguments:
|
||||
local_path(str): Path to the local file to push.
|
||||
remote_path(str): Path or directory to store the file on the device.
|
||||
"""
|
||||
msg = "Pushing %r to %r" % (local_path, remote_path)
|
||||
|
||||
if context.log_level == 'debug':
|
||||
msg += ' (%s)' % context.device
|
||||
|
||||
with log.waitfor(msg) as w:
|
||||
with context.quiet:
|
||||
args = context.adb + ['push', local_path, remote_path]
|
||||
io = tubes.process.process(args)
|
||||
result = io.recvall()
|
||||
|
||||
if 0 != io.poll(block=True):
|
||||
log.error(result)
|
||||
|
||||
return result
|
||||
|
||||
@context.quiet
|
||||
def read(path, target=None):
|
||||
"""Download a file from the device, and extract its contents.
|
||||
|
||||
Arguments:
|
||||
path(str): Path to the file on the device.
|
||||
target(str): Optional, location to store the file.
|
||||
Uses a temporary file by default.
|
||||
"""
|
||||
with tempfile.NamedTemporaryFile() as temp:
|
||||
target = target or temp.name
|
||||
pull(path, target)
|
||||
result = misc.read(target)
|
||||
return result
|
||||
|
||||
@context.quiet
|
||||
def write(path, data=''):
|
||||
"""Create a file on the device with the provided contents.
|
||||
|
||||
Arguments:
|
||||
path(str): Path to the file on the device
|
||||
data(str): Contents to store in the file
|
||||
"""
|
||||
with tempfile.NamedTemporaryFile() as temp:
|
||||
misc.write(temp.name, data)
|
||||
push(temp.name, path)
|
||||
|
||||
def process(argv, *a, **kw):
|
||||
"""Execute a process on the device.
|
||||
|
||||
See ``pwnlib.tubes.process.process`` documentation for more info.
|
||||
|
||||
Returns:
|
||||
A ``process`` tube.
|
||||
"""
|
||||
argv = argv or []
|
||||
if isinstance(argv, (str, unicode)):
|
||||
argv = [argv]
|
||||
|
||||
display = argv
|
||||
argv = context.adb + ['shell'] + argv
|
||||
|
||||
kw.setdefault('display', display)
|
||||
kw.setdefault('where', 'Android')
|
||||
|
||||
return tubes.process.process(argv, *a, **kw)
|
||||
|
||||
def interactive(**kw):
|
||||
"""Spawns an interactive shell."""
|
||||
return shell(**kw).interactive()
|
||||
|
||||
def shell(**kw):
|
||||
"""Returns an interactive shell."""
|
||||
return process([], **kw)
|
||||
|
||||
@context.quiet
|
||||
def which(name):
|
||||
"""Retrieves the full path to a binary in ``PATH`` on the device"""
|
||||
return process(['which', name]).recvall().strip()
|
||||
|
||||
def whoami():
|
||||
return process(['whoami']).recvall().strip()
|
||||
|
||||
def forward(port):
|
||||
"""Sets up a port to forward to the device."""
|
||||
tcp_port = 'tcp:%s' % port
|
||||
start_forwarding = adb(['forward', tcp_port, tcp_port])
|
||||
atexit.register(lambda: adb(['forward', '--remove', tcp_port]))
|
||||
|
||||
@context.quiet
|
||||
def logcat(stream=False):
|
||||
"""Reads the system log file.
|
||||
|
||||
By default, causes logcat to exit after reading the file.
|
||||
|
||||
Arguments:
|
||||
stream(bool): If ``True``, the contents are streamed rather than
|
||||
read in a one-shot manner. Default is ``False``.
|
||||
|
||||
Returns:
|
||||
If ``stream`` is ``False``, returns a string containing the log data.
|
||||
Otherwise, it returns a ``tube`` connected to the log output.
|
||||
"""
|
||||
|
||||
if stream:
|
||||
return process(['logcat'])
|
||||
else:
|
||||
return adb(['logcat', '-d'])
|
||||
|
||||
def pidof(name):
|
||||
"""Returns a list of PIDs for the named process."""
|
||||
with context.quiet:
|
||||
io = process(['pidof', name])
|
||||
data = io.recvall().split()
|
||||
return list(map(int, data))
|
||||
|
||||
def proc_exe(pid):
|
||||
"""Returns the full path of the executable for the provided PID."""
|
||||
with context.quiet:
|
||||
io = process(['readlink','-e','/proc/%d/exe' % pid])
|
||||
data = io.recvall().strip()
|
||||
return data
|
||||
|
||||
def getprop(name=None):
|
||||
"""Reads a properties from the system property store.
|
||||
|
||||
Arguments:
|
||||
name(str): Optional, read a single property.
|
||||
|
||||
Returns:
|
||||
If ``name`` is not specified, a ``dict`` of all properties is returned.
|
||||
Otherwise, a string is returned with the contents of the named property.
|
||||
"""
|
||||
with context.quiet:
|
||||
if name:
|
||||
return process(['getprop', name]).recvall().strip()
|
||||
|
||||
|
||||
result = process(['getprop']).recvall()
|
||||
|
||||
expr = r'\[([^\]]+)\]: \[(.*)\]'
|
||||
|
||||
props = {}
|
||||
|
||||
for line in result.splitlines():
|
||||
if not line.startswith('['):
|
||||
continue
|
||||
|
||||
name, value = re.search(expr, line).groups()
|
||||
|
||||
if value.isdigit():
|
||||
value = int(value)
|
||||
|
||||
props[name] = value
|
||||
|
||||
return props
|
||||
|
||||
def setprop(name, value):
|
||||
"""Writes a property to the system property store."""
|
||||
return process(['setprop', name, value]).recvall().strip()
|
||||
|
||||
def listdir(directory='/'):
|
||||
"""Returns a list containing the entries in the provided directory.
|
||||
|
||||
Note:
|
||||
Because ``adb shell`` is used to retrieve the listing, shell
|
||||
environment variable expansion and globbing are in effect.
|
||||
"""
|
||||
io = process(['find', directory, '-maxdepth', '1', '-print0'])
|
||||
data = io.recvall()
|
||||
paths = filter(len, data.split('\x00'))
|
||||
relpaths = [os.path.relpath(path, directory) for path in paths]
|
||||
if '.' in relpaths:
|
||||
relpaths.remove('.')
|
||||
return relpaths
|
||||
|
||||
def fastboot(args, *a, **kw):
|
||||
"""Executes a fastboot command.
|
||||
|
||||
Returns:
|
||||
The command output.
|
||||
"""
|
||||
serial = context.device
|
||||
if not serial:
|
||||
log.error("Unknown device")
|
||||
return tubes.process.process(['fastboot', '-s', serial] + list(args), **kw).recvall()
|
||||
|
||||
def fingerprint():
|
||||
"""Returns the device build fingerprint."""
|
||||
return str(properties.ro.build.fingerprint)
|
||||
|
||||
def product():
|
||||
"""Returns the device product identifier."""
|
||||
return str(properties.ro.build.product)
|
||||
|
||||
def build():
|
||||
"""Returns the Build ID of the device."""
|
||||
return str(properties.ro.build.id)
|
||||
|
||||
def unlock_bootloader():
|
||||
"""Unlocks the bootloader of the device.
|
||||
|
||||
Note:
|
||||
This requires physical interaction with the device.
|
||||
"""
|
||||
adb(['reboot-bootloader'])
|
||||
fastboot(['oem', 'unlock'])
|
||||
fastboot(['continue'])
|
||||
|
||||
class Kernel(object):
|
||||
_kallsyms = None
|
||||
|
||||
@property
|
||||
def address(self):
|
||||
return self.symbols['_text']
|
||||
|
||||
@property
|
||||
@context.quiet
|
||||
def symbols(self):
|
||||
"""Returns a dictionary of kernel symbols"""
|
||||
result = {}
|
||||
for line in self.kallsyms.splitlines():
|
||||
fields = line.split()
|
||||
address = int(fields[0], 16)
|
||||
name = fields[-1]
|
||||
result[name] = address
|
||||
return result
|
||||
|
||||
@property
|
||||
@context.quiet
|
||||
def kallsyms(self):
|
||||
"""Returns the raw output of kallsyms"""
|
||||
if not self._kallsyms:
|
||||
self._kallsyms = {}
|
||||
root()
|
||||
write('/proc/sys/kernel/kptr_restrict', '1')
|
||||
self._kallsyms = read('/proc/kallsyms')
|
||||
return self._kallsyms
|
||||
|
||||
@property
|
||||
@context.quiet
|
||||
def version(self):
|
||||
"""Returns the kernel version of the device."""
|
||||
root()
|
||||
return read('/proc/version').strip()
|
||||
|
||||
@property
|
||||
@context.quiet
|
||||
def cmdline(self):
|
||||
root()
|
||||
return read('/proc/cmdline').strip()
|
||||
|
||||
@property
|
||||
@context.quiet
|
||||
def lastmsg(self):
|
||||
root()
|
||||
if 'last_kmsg' in listdir('/proc'):
|
||||
return read('/proc/last_kmsg')
|
||||
|
||||
if 'console-ramoops' in listdir('/sys/fs/pstore/'):
|
||||
return read('/sys/fs/pstore/console-ramoops')
|
||||
|
||||
def enable_uart(self):
|
||||
"""Reboots the device with kernel logging to the UART enabled."""
|
||||
model = str(properties.ro.product.model)
|
||||
|
||||
known_commands = {
|
||||
'Nexus 4': None,
|
||||
'Nexus 5': None,
|
||||
'Nexus 6': 'oem config console enable',
|
||||
'Nexus 5X': None,
|
||||
'Nexus 6P': 'oem uart enable',
|
||||
'Nexus 7': 'oem uart-on',
|
||||
}
|
||||
|
||||
with log.waitfor('Enabling kernel UART') as w:
|
||||
|
||||
if model not in known_commands:
|
||||
log.error("Device UART is unsupported.")
|
||||
|
||||
command = known_commands[model]
|
||||
|
||||
if command is None:
|
||||
w.success('Always enabled')
|
||||
return
|
||||
|
||||
# Check the current commandline, it may already be enabled.
|
||||
if any(s.startswith('console=tty') for s in self.cmdline.split()):
|
||||
w.success("Already enabled")
|
||||
return
|
||||
|
||||
# Need to be root
|
||||
with context.local(device=context.device):
|
||||
# Save off the command line before rebooting to the bootloader
|
||||
cmdline = kernel.cmdline
|
||||
|
||||
reboot_bootloader()
|
||||
|
||||
# Wait for device to come online
|
||||
while context.device not in fastboot(['devices',' -l']):
|
||||
time.sleep(0.5)
|
||||
|
||||
# Try the 'new' way
|
||||
fastboot(command.split())
|
||||
fastboot(['continue'])
|
||||
wait_for_device()
|
||||
|
||||
|
||||
kernel = Kernel()
|
||||
|
||||
class Property(object):
|
||||
def __init__(self, name=None):
|
||||
self.__dict__['_name'] = name
|
||||
|
||||
def __str__(self):
|
||||
return getprop(self._name).strip()
|
||||
|
||||
def __repr__(self):
|
||||
return repr(str(self))
|
||||
|
||||
def __getattr__(self, attr):
|
||||
if self._name:
|
||||
attr = '%s.%s' % (self._name, attr)
|
||||
return Property(attr)
|
||||
|
||||
def __setattr__(self, attr, value):
|
||||
if attr in self.__dict__:
|
||||
return super(Property, self).__setattr__(attr, value)
|
||||
|
||||
if self._name:
|
||||
attr = '%s.%s' % (self._name, attr)
|
||||
setprop(attr, value)
|
||||
|
||||
properties = Property()
|
||||
|
||||
def _build_date():
|
||||
"""Returns the build date in the form YYYY-MM-DD as a string"""
|
||||
as_string = getprop('ro.build.date')
|
||||
as_datetime = dateutil.parser.parse(as_string)
|
||||
return as_datetime.strftime('%Y-%b-%d')
|
||||
|
||||
def find_ndk_project_root(source):
|
||||
'''Given a directory path, find the topmost project root.
|
||||
|
||||
tl;dr "foo/bar/jni/baz.cpp" ==> "foo/bar"
|
||||
'''
|
||||
ndk_directory = os.path.abspath(source)
|
||||
while ndk_directory != '/':
|
||||
if os.path.exists(os.path.join(ndk_directory, 'jni')):
|
||||
break
|
||||
ndk_directory = os.path.dirname(ndk_directory)
|
||||
else:
|
||||
return None
|
||||
|
||||
return ndk_directory
|
||||
|
||||
_android_mk_template = '''
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
LOCAL_MODULE := poc
|
||||
LOCAL_SRC_FILES := %(local_src_files)s
|
||||
|
||||
include $(BUILD_EXECUTABLE)
|
||||
'''.lstrip()
|
||||
|
||||
_application_mk_template = '''
|
||||
LOCAL_PATH := $(call my-dir)
|
||||
|
||||
include $(CLEAR_VARS)
|
||||
APP_ABI:= %(app_abi)s
|
||||
APP_PLATFORM:=%(app_platform)s
|
||||
'''.lstrip()
|
||||
|
||||
def _generate_ndk_project(file_list, abi='arm-v7a', platform_version=21):
|
||||
# Create our project root
|
||||
root = tempfile.mkdtemp()
|
||||
|
||||
if not isinstance(file_list, (list, tuple)):
|
||||
file_list = [file_list]
|
||||
|
||||
# Copy over the source file(s)
|
||||
jni_directory = os.path.join(root, 'jni')
|
||||
os.mkdir(jni_directory)
|
||||
for file in file_list:
|
||||
shutil.copy(file, jni_directory)
|
||||
|
||||
# Create the directories
|
||||
|
||||
# Populate Android.mk
|
||||
local_src_files = ' '.join(list(map(os.path.basename, file_list)))
|
||||
Android_mk = os.path.join(jni_directory, 'Android.mk')
|
||||
with open(Android_mk, 'w+') as f:
|
||||
f.write(_android_mk_template % locals())
|
||||
|
||||
# Populate Application.mk
|
||||
app_abi = abi
|
||||
app_platform = 'android-%s' % platform_version
|
||||
Application_mk = os.path.join(jni_directory, 'Application.mk')
|
||||
with open(Application_mk, 'w+') as f:
|
||||
f.write(_application_mk_template % locals())
|
||||
|
||||
return root
|
||||
|
||||
def compile(source):
|
||||
"""Compile a source file or project with the Android NDK."""
|
||||
|
||||
# Ensure that we can find the NDK.
|
||||
ndk = os.environ.get('NDK', None)
|
||||
if ndk is None:
|
||||
log.error('$NDK must be set to the Android NDK directory')
|
||||
ndk_build = os.path.join(ndk, 'ndk-build')
|
||||
|
||||
# Determine whether the source is an NDK project or a single source file.
|
||||
project = find_ndk_project_root(source)
|
||||
|
||||
if not project:
|
||||
project = _generate_ndk_project(source,
|
||||
str(properties.ro.product.cpu.abi),
|
||||
str(properties.ro.build.version.sdk))
|
||||
|
||||
# Remove any output files
|
||||
lib = os.path.join(project, 'libs')
|
||||
if os.path.exists(lib):
|
||||
shutil.rmtree(lib)
|
||||
|
||||
# Build the project
|
||||
io = tubes.process.process(ndk_build, cwd=os.path.join(project, 'jni'))
|
||||
|
||||
result = io.recvall()
|
||||
|
||||
if 0 != io.poll():
|
||||
log.error("Build failed:\n%s" % result)
|
||||
|
||||
# Find all of the output files
|
||||
output = glob.glob(os.path.join(lib, '*', '*'))
|
||||
|
||||
return output[0]
|
||||
|
||||
class Partition(object):
|
||||
def __init__(self, path, name, blocks=0):
|
||||
self.path = path
|
||||
self.name = name
|
||||
self.blocks = blocks
|
||||
self.size = blocks * 1024
|
||||
|
||||
@property
|
||||
def data(self):
|
||||
with log.waitfor('Fetching %r partition (%s)' % (self.name, self.path)):
|
||||
return read(self.path)
|
||||
|
||||
class Partitions(object):
|
||||
@property
|
||||
@context.quiet
|
||||
def by_name_dir(self):
|
||||
cmd = ['shell','find /dev/block/platform -type d -name by-name']
|
||||
return adb(cmd).strip()
|
||||
|
||||
@context.quiet
|
||||
def __dir__(self):
|
||||
return list(self)
|
||||
|
||||
@context.quiet
|
||||
def __iter__(self):
|
||||
root()
|
||||
|
||||
# Find all named partitions
|
||||
for name in listdir(self.by_name_dir):
|
||||
yield name
|
||||
|
||||
@context.quiet
|
||||
def __getattr__(self, attr):
|
||||
for name in self:
|
||||
if name == attr:
|
||||
break
|
||||
else:
|
||||
raise AttributeError("No partition %r" % attr)
|
||||
|
||||
path = os.path.join(self.by_name_dir, name)
|
||||
|
||||
# Find the actual path of the device
|
||||
devpath = process(['readlink', '-n', path]).recvall()
|
||||
devname = os.path.basename(devpath)
|
||||
|
||||
# Get the size of the partition
|
||||
for line in read('/proc/partitions').splitlines():
|
||||
if not line.strip():
|
||||
continue
|
||||
major, minor, blocks, name = line.split(None, 4)
|
||||
if devname == name:
|
||||
break
|
||||
else:
|
||||
log.error("Could not find size of partition %r" % name)
|
||||
|
||||
return Partition(devpath, attr, int(blocks))
|
||||
|
||||
partitions = Partitions()
|
||||
@@ -0,0 +1,4 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
from pwnlib.adb.adb import *
|
||||
from pwnlib.adb.protocol import Client
|
||||
+1383
File diff suppressed because it is too large.
Load diff
@@ -0,0 +1,5 @@
|
||||
"""
|
||||
This file exists only for backward compatibility
|
||||
"""
|
||||
from pwnlib.protocols.adb import AdbClient
|
||||
Client = AdbClient
|
||||
+96
-23
@@ -1,18 +1,70 @@
|
||||
|
||||
#!/usr/bin/env python2
|
||||
"""
|
||||
Pwntools exposes several magic command-line arguments and environment
|
||||
variables when operating in `from pwn import *` mode.
|
||||
|
||||
The arguments extracted from the command-line and removed from ``sys.argv``.
|
||||
|
||||
Arguments can be set by appending them to the command-line, or setting
|
||||
them in the environment prefixed by ``PWNLIB_``.
|
||||
|
||||
The easiest example is to enable more verbose debugging. Just set ``DEBUG``.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ PWNLIB_DEBUG=1 python exploit.py
|
||||
$ python exploit.py DEBUG
|
||||
|
||||
These arguments are automatically extracted, regardless of their name, and
|
||||
exposed via :mod:`pwnlib.args.args`, which is exposed as the global variable
|
||||
:data:`args`. Arguments which ``pwntools`` reserves internally are not exposed
|
||||
this way.
|
||||
|
||||
.. code-block:: bash
|
||||
|
||||
$ python -c 'from pwn import *; print args' A=1 B=Hello HOST=1.2.3.4 DEBUG
|
||||
defaultdict(<type 'str'>, {'A': '1', 'HOST': '1.2.3.4', 'B': 'Hello'})
|
||||
|
||||
This is very useful for conditional code, for example determining whether to
|
||||
run an exploit locally or to connect to a remote server. Arguments which are
|
||||
not specified evaluate to an empty string.
|
||||
|
||||
.. code-block:: python
|
||||
|
||||
if args['REMOTE']:
|
||||
io = remote('exploitme.com', 4141)
|
||||
else:
|
||||
io = process('./pwnable')
|
||||
|
||||
The full list of supported "magic arguments" and their effects are listed
|
||||
below.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import collections
|
||||
import logging
|
||||
import os
|
||||
import string
|
||||
import sys
|
||||
|
||||
from . import term
|
||||
from .context import context
|
||||
from pwnlib import term
|
||||
from pwnlib.context import context
|
||||
|
||||
term_mode = True
|
||||
args = collections.defaultdict(str)
|
||||
env_prefix = 'PWNLIB_'
|
||||
free_form = True
|
||||
|
||||
# Check to see if we were invoked as one of the 'pwn xxx' scripts.
|
||||
# If so, we don't want to remove e.g. "SYS_" from the end of the command
|
||||
# line, as this breaks things like constgrep.
|
||||
import pwnlib.commandline
|
||||
basename = os.path.basename(sys.argv[0])
|
||||
|
||||
if basename == 'pwn' or basename in pwnlib.commandline.__all__:
|
||||
free_form = False
|
||||
|
||||
|
||||
def isident(s):
|
||||
"""
|
||||
@@ -42,46 +94,67 @@ def asbool(s):
|
||||
else:
|
||||
raise ValueError('must be integer or boolean: %r' % s)
|
||||
|
||||
def set_log_level(x):
|
||||
def LOG_LEVEL(x):
|
||||
"""Sets the logging verbosity used via ``context.log_level``,
|
||||
e.g. ``LOG_LEVEL=debug``.
|
||||
"""
|
||||
with context.local(log_level=x):
|
||||
context.defaults['log_level']=context.log_level
|
||||
|
||||
def set_log_file(x):
|
||||
def LOG_FILE(x):
|
||||
"""Sets a log file to be used via ``context.log_file``, e.g.
|
||||
``LOG_FILE=./log.txt``"""
|
||||
context.log_file=x
|
||||
|
||||
def set_log_level_error(x):
|
||||
set_log_level('error')
|
||||
def SILENT(x):
|
||||
"""Sets the logging verbosity to ``error`` which silences most
|
||||
output."""
|
||||
LOG_LEVEL('error')
|
||||
|
||||
def set_log_level_debug(x):
|
||||
set_log_level('debug')
|
||||
def DEBUG(x):
|
||||
"""Sets the logging verbosity to ``debug`` which displays much
|
||||
more information, including logging each byte sent by tubes."""
|
||||
LOG_LEVEL('debug')
|
||||
|
||||
def set_noterm(v):
|
||||
def NOTERM(v):
|
||||
"""Disables pretty terminal settings and animations."""
|
||||
if asbool(v):
|
||||
global term_mode
|
||||
term_mode = False
|
||||
|
||||
def set_timeout(v):
|
||||
def TIMEOUT(v):
|
||||
"""Sets a timeout for tube operations (in seconds) via
|
||||
``context.timeout``, e.g. ``TIMEOUT=30``"""
|
||||
context.defaults['timeout'] = int(v)
|
||||
|
||||
def set_randomize(v):
|
||||
def RANDOMIZE(v):
|
||||
"""Enables randomization of various pieces via ``context.randomize``"""
|
||||
context.defaults['randomize'] = asbool(v)
|
||||
|
||||
def set_aslr(v):
|
||||
def NOASLR(v):
|
||||
"""Disables ASLR via ``context.aslr``"""
|
||||
context.defaults['aslr'] = not asbool(v)
|
||||
|
||||
def set_noptrace(v):
|
||||
def NOPTRACE(v):
|
||||
"""Disables facilities which require ``ptrace`` such as ``gdb.attach()``
|
||||
statements, via ``context.noptrace``."""
|
||||
context.defaults['noptrace'] = asbool(v)
|
||||
|
||||
def STDERR(v):
|
||||
"""Sends logging to ``stderr`` by default, instead of ``stdout``"""
|
||||
context.log_console = sys.stderr
|
||||
|
||||
hooks = {
|
||||
'LOG_LEVEL': set_log_level,
|
||||
'LOG_FILE': set_log_file,
|
||||
'DEBUG': set_log_level_debug,
|
||||
'NOTERM': set_noterm,
|
||||
'SILENT': set_log_level_error,
|
||||
'RANDOMIZE': set_randomize,
|
||||
'TIMEOUT': set_timeout,
|
||||
'NOASLR': set_aslr,
|
||||
'NOPTRACE': set_noptrace,
|
||||
'LOG_LEVEL': LOG_LEVEL,
|
||||
'LOG_FILE': LOG_FILE,
|
||||
'DEBUG': DEBUG,
|
||||
'NOTERM': NOTERM,
|
||||
'SILENT': SILENT,
|
||||
'RANDOMIZE': RANDOMIZE,
|
||||
'TIMEOUT': TIMEOUT,
|
||||
'NOASLR': NOASLR,
|
||||
'NOPTRACE': NOPTRACE,
|
||||
'STDERR': STDERR,
|
||||
}
|
||||
|
||||
def initialize():
|
||||
@@ -113,7 +186,7 @@ def initialize():
|
||||
sys.argv.remove(orig)
|
||||
hooks[arg](value)
|
||||
|
||||
elif isident(arg):
|
||||
elif free_form and isident(arg):
|
||||
sys.argv.remove(orig)
|
||||
args[arg] = value
|
||||
|
||||
|
||||
+207
-93
@@ -27,8 +27,8 @@ Assembly
|
||||
Finally, :func:`asm` is used to assemble shellcode provided by ``pwntools``
|
||||
in the :mod:`shellcraft` module.
|
||||
|
||||
>>> asm(shellcraft.sh())
|
||||
'jhh///sh/binj\x0bX\x89\xe31\xc9\x99\xcd\x80'
|
||||
>>> asm(shellcraft.nop())
|
||||
'\x90'
|
||||
|
||||
Disassembly
|
||||
------------------------
|
||||
@@ -39,6 +39,8 @@ Disassembly
|
||||
' 0: b8 0b 00 00 00 mov eax,0xb'
|
||||
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import errno
|
||||
import os
|
||||
import platform
|
||||
@@ -53,11 +55,11 @@ from glob import glob
|
||||
from os import environ
|
||||
from os import path
|
||||
|
||||
from . import atexit
|
||||
from . import shellcraft
|
||||
from .context import LocalContext
|
||||
from .context import context
|
||||
from .log import getLogger
|
||||
from pwnlib import atexit
|
||||
from pwnlib import shellcraft
|
||||
from pwnlib.context import LocalContext
|
||||
from pwnlib.context import context
|
||||
from pwnlib.log import getLogger
|
||||
|
||||
log = getLogger(__name__)
|
||||
|
||||
@@ -66,6 +68,75 @@ __all__ = ['asm', 'cpp', 'disasm', 'make_elf', 'make_elf_from_assembly']
|
||||
_basedir = path.split(__file__)[0]
|
||||
_incdir = path.join(_basedir, 'data', 'includes')
|
||||
|
||||
def dpkg_search_for_binutils(arch, util):
|
||||
"""Use dpkg to search for any available assemblers which will work.
|
||||
|
||||
Returns:
|
||||
A list of candidate package names.
|
||||
|
||||
::
|
||||
|
||||
>>> pwnlib.asm.dpkg_search_for_binutils('aarch64', 'as')
|
||||
['binutils-aarch64-linux-gnu']
|
||||
"""
|
||||
|
||||
# Example output:
|
||||
# $ dpkg -S 'arm*linux*-as'
|
||||
# binutils-arm-linux-gnu: /usr/bin/arm-linux-gnu-as
|
||||
# binutils-arm-linux-gnueabihf: /usr/bin/arm-linux-gnueabihf-as
|
||||
# binutils-arm-linux-gnueabihf: /usr/x86_64-linux-gnu/arm-linux-gnueabihf/include/dis-asm.h
|
||||
# binutils-arm-linux-gnu: /usr/x86_64-linux-gnu/arm-linux-gnu/include/dis-asm.h
|
||||
packages = []
|
||||
|
||||
try:
|
||||
filename = 'bin/%s*linux*-%s' % (arch, util)
|
||||
output = subprocess.check_output(['dpkg','-S',filename])
|
||||
for line in output.strip().splitlines():
|
||||
package, path = line.split(':', 1)
|
||||
packages.append(package)
|
||||
except OSError:
|
||||
pass
|
||||
except subprocess.CalledProcessError:
|
||||
pass
|
||||
|
||||
return packages
|
||||
|
||||
def print_binutils_instructions(util, context):
|
||||
"""On failure to find a binutils utility, inform the user of a way
|
||||
they can get it easily.
|
||||
|
||||
Doctest:
|
||||
|
||||
>>> context.clear(arch = 'amd64')
|
||||
>>> pwnlib.asm.print_binutils_instructions('as', context)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
PwnlibException: Could not find 'as' installed for ContextType(arch = 'amd64', bits = 64, endian = 'little')
|
||||
Try installing binutils for this architecture:
|
||||
$ sudo apt-get install binutils
|
||||
"""
|
||||
# This links to our instructions on how to manually install binutils
|
||||
# for several architectures.
|
||||
instructions = 'https://docs.pwntools.com/en/stable/install/binutils.html'
|
||||
|
||||
# However, if we can directly provide a useful command, go for it.
|
||||
binutils_arch = {
|
||||
'amd64': 'x86_64',
|
||||
'arm': 'armeabi',
|
||||
'thumb': 'armeabi',
|
||||
}.get(context.arch, context.arch)
|
||||
|
||||
packages = dpkg_search_for_binutils(binutils_arch, util)
|
||||
|
||||
if packages:
|
||||
instructions = '$ sudo apt-get install %s' % packages[0]
|
||||
|
||||
log.error("""
|
||||
Could not find %(util)r installed for %(context)s
|
||||
Try installing binutils for this architecture:
|
||||
%(instructions)s
|
||||
""".strip() % locals())
|
||||
|
||||
@LocalContext
|
||||
def which_binutils(util):
|
||||
"""
|
||||
@@ -119,23 +190,20 @@ def which_binutils(util):
|
||||
for arch in arches:
|
||||
for gutil in utils:
|
||||
# e.g. objdump
|
||||
if arch is None: pattern = gutil
|
||||
if arch is None:
|
||||
pattern = gutil
|
||||
|
||||
# e.g. aarch64-linux-gnu-objdump
|
||||
else: pattern = '%s*linux*-%s' % (arch,gutil)
|
||||
else:
|
||||
pattern = '%s*linux*-%s' % (arch,gutil)
|
||||
|
||||
for dir in environ['PATH'].split(':'):
|
||||
res = sorted(glob(path.join(dir, pattern)))
|
||||
if res:
|
||||
return res[0]
|
||||
|
||||
locals()['context'] = context
|
||||
log.warning("""
|
||||
Could not find %(util)r installed for %(context)s
|
||||
Try installing binutils for this architecture:
|
||||
https://docs.pwntools.com/en/stable/install/binutils.html
|
||||
""".strip() % locals())
|
||||
raise Exception('Could not find %(util)r installed for %(context)s' % locals())
|
||||
# No dice!
|
||||
print_binutils_instructions(util, context)
|
||||
|
||||
checked_assembler_version = defaultdict(lambda: False)
|
||||
|
||||
@@ -331,16 +399,14 @@ def cpp(shellcode):
|
||||
|
||||
Examples:
|
||||
|
||||
.. doctest::
|
||||
|
||||
>>> cpp("mov al, SYS_setresuid", arch = "i386", os = "linux")
|
||||
'mov al, 164\n'
|
||||
>>> cpp("weee SYS_setresuid", arch = "arm", os = "linux")
|
||||
'weee (0+164)\n'
|
||||
>>> cpp("SYS_setresuid", arch = "thumb", os = "linux")
|
||||
'(0+164)\n'
|
||||
>>> cpp("SYS_setresuid", os = "freebsd")
|
||||
'311\n'
|
||||
>>> cpp("mov al, SYS_setresuid", arch = "i386", os = "linux")
|
||||
'mov al, 164\n'
|
||||
>>> cpp("weee SYS_setresuid", arch = "arm", os = "linux")
|
||||
'weee (0+164)\n'
|
||||
>>> cpp("SYS_setresuid", arch = "thumb", os = "linux")
|
||||
'(0+164)\n'
|
||||
>>> cpp("SYS_setresuid", os = "freebsd")
|
||||
'311\n'
|
||||
"""
|
||||
arch = context.arch
|
||||
os = context.os
|
||||
@@ -357,17 +423,39 @@ def cpp(shellcode):
|
||||
return _run(cmd, code).strip('\n').rstrip() + '\n'
|
||||
|
||||
@LocalContext
|
||||
def make_elf_from_assembly(assembly, vma = None, extract=False, shared = False):
|
||||
r"""
|
||||
Builds an ELF file with the specified assembly as its
|
||||
executable code.
|
||||
def make_elf_from_assembly(assembly,
|
||||
vma=None,
|
||||
extract=False,
|
||||
shared=False,
|
||||
strip=False,
|
||||
**kwargs):
|
||||
r"""make_elf_from_assembly(assembly, vma=None, extract=None, shared=False, strip=False, **kwargs) -> str
|
||||
|
||||
Builds an ELF file with the specified assembly as its executable code.
|
||||
|
||||
This differs from :func:`.make_elf` in that all ELF symbols are preserved,
|
||||
such as labels and local variables. Use :func:`.make_elf` if size matters.
|
||||
Additionally, the default value for ``extract`` in :func:`.make_elf` is
|
||||
different.
|
||||
|
||||
Note:
|
||||
This is effectively a wrapper around :func:`.asm`. with setting
|
||||
``extract=False``, ``vma=0x10000000``, and marking the resulting
|
||||
file as executable (``chmod +x``).
|
||||
|
||||
Note:
|
||||
ELF files created with `arch=thumb` will prepend an ARM stub
|
||||
which switches to Thumb mode.
|
||||
|
||||
Arguments:
|
||||
|
||||
assembly(str): Assembly
|
||||
assembly(str): Assembly code to build into an ELF
|
||||
vma(int): Load address of the binary
|
||||
extract(bool): Whether to return the data extracted from the file created,
|
||||
or the path to it.
|
||||
(Default: ``0x10000000``, or ``0`` if ``shared=True``)
|
||||
extract(bool): Extract the full ELF data from the file.
|
||||
(Default: ``False``)
|
||||
shared(bool): Create a shared library
|
||||
(Default: ``False``)
|
||||
kwargs(dict): Arguments to pass to :func:`.asm`.
|
||||
|
||||
Returns:
|
||||
|
||||
@@ -376,6 +464,9 @@ def make_elf_from_assembly(assembly, vma = None, extract=False, shared = False):
|
||||
|
||||
Example:
|
||||
|
||||
This example shows how to create a shared library, and load it via
|
||||
``LD_PRELOAD``.
|
||||
|
||||
>>> context.clear()
|
||||
>>> context.arch = 'amd64'
|
||||
>>> sc = 'push rbp; mov rbp, rsp;'
|
||||
@@ -384,6 +475,18 @@ def make_elf_from_assembly(assembly, vma = None, extract=False, shared = False):
|
||||
>>> solib = make_elf_from_assembly(sc, shared=1)
|
||||
>>> subprocess.check_output(['echo', 'World'], env={'LD_PRELOAD': solib})
|
||||
'Hello\nWorld\n'
|
||||
|
||||
The same thing can be done with :func:`.make_elf`, though the sizes
|
||||
are different. They both
|
||||
|
||||
>>> file_a = make_elf(asm('nop'), extract=True)
|
||||
>>> file_b = make_elf_from_assembly('nop', extract=True)
|
||||
>>> file_a[:4] == file_b[:4]
|
||||
True
|
||||
>>> len(file_a) < 0x200
|
||||
True
|
||||
>>> len(file_b) > 0x1000
|
||||
True
|
||||
"""
|
||||
if shared and vma:
|
||||
log.error("Cannot specify a VMA for a shared library.")
|
||||
@@ -400,38 +503,44 @@ def make_elf_from_assembly(assembly, vma = None, extract=False, shared = False):
|
||||
if not assembly.startswith(to_thumb):
|
||||
assembly = to_thumb + assembly
|
||||
|
||||
path = asm(assembly, vma = vma, extract = extract, shared = shared)
|
||||
result = asm(assembly, vma = vma, shared = shared, extract = False, **kwargs)
|
||||
|
||||
if not extract:
|
||||
os.chmod(path, 0755)
|
||||
os.chmod(result, 0755)
|
||||
else:
|
||||
with open(result, 'rb') as io:
|
||||
result = io.read()
|
||||
|
||||
return path
|
||||
return result
|
||||
|
||||
@LocalContext
|
||||
def make_elf(data, vma = None, strip=True, extract=True, shared=False):
|
||||
r"""
|
||||
Builds an ELF file with the specified binary data as its
|
||||
executable code.
|
||||
def make_elf(data,
|
||||
vma=None,
|
||||
strip=True,
|
||||
extract=True,
|
||||
shared=False):
|
||||
r"""make_elf(data, vma=None, strip=True, extract=True, shared=False, **kwargs) -> str
|
||||
|
||||
Builds an ELF file with the specified binary data as its executable code.
|
||||
|
||||
Arguments:
|
||||
data(str): Assembled code
|
||||
vma(int): Load address for the ELF file
|
||||
strip(bool): Strip the resulting ELF file. Only matters if ``extract=False``.
|
||||
(Default: ``True``)
|
||||
extract(bool): Extract the assembly from the ELF file.
|
||||
If ``False``, the path of the ELF file is returned.
|
||||
(Default: ``True``)
|
||||
shared(bool): Create a Dynamic Shared Object (DSO, i.e. a ``.so``)
|
||||
which can be loaded via ``dlopen`` or ``LD_PRELOAD``.
|
||||
|
||||
Examples:
|
||||
|
||||
This example creates an i386 ELF that just does
|
||||
execve('/bin/sh',...).
|
||||
|
||||
>>> context.clear()
|
||||
>>> context.arch = 'i386'
|
||||
>>> context.bits = 32
|
||||
>>> filename = tempfile.mktemp()
|
||||
>>> context.clear(arch='i386')
|
||||
>>> bin_sh = '6a68682f2f2f73682f62696e89e331c96a0b5899cd80'.decode('hex')
|
||||
>>> data = make_elf(bin_sh)
|
||||
>>> with open(filename,'wb+') as f:
|
||||
... f.write(data)
|
||||
... f.flush()
|
||||
>>> os.chmod(filename,0777)
|
||||
>>> filename = make_elf(bin_sh, extract=False)
|
||||
>>> p = process(filename)
|
||||
>>> p.sendline('echo Hello; exit')
|
||||
>>> p.recvline()
|
||||
@@ -499,38 +608,37 @@ def make_elf(data, vma = None, strip=True, extract=True, shared=False):
|
||||
|
||||
@LocalContext
|
||||
def asm(shellcode, vma = 0, extract = True, shared = False):
|
||||
r"""asm(code, vma = 0, extract = True, ...) -> str
|
||||
r"""asm(code, vma = 0, extract = True, shared = False, ...) -> str
|
||||
|
||||
Runs :func:`cpp` over a given shellcode and then assembles it into bytes.
|
||||
|
||||
To see which architectures or operating systems are supported,
|
||||
look in :mod:`pwnlib.contex`.
|
||||
|
||||
To support all these architecture, we bundle the GNU assembler
|
||||
and objcopy with pwntools.
|
||||
Assembling shellcode requires that the GNU assembler is installed
|
||||
for the target architecture.
|
||||
See :doc:`Installing Binutils </install/binutils>` for more information.
|
||||
|
||||
Arguments:
|
||||
shellcode(str): Assembler code to assemble.
|
||||
vma(int): Virtual memory address of the beginning of assembly
|
||||
extract(bool): Extract the raw assembly bytes from the assembled
|
||||
file. If ``False``, returns the path to an ELF file
|
||||
with the assembly embedded.
|
||||
|
||||
Kwargs:
|
||||
Any arguments/properties that can be set on ``context``
|
||||
shellcode(str): Assembler code to assemble.
|
||||
vma(int): Virtual memory address of the beginning of assembly
|
||||
extract(bool): Extract the raw assembly bytes from the assembled
|
||||
file. If :const:`False`, returns the path to an ELF file
|
||||
with the assembly embedded.
|
||||
shared(bool): Create a shared object.
|
||||
kwargs(dict): Any attributes on :data:`.context` can be set, e.g.set
|
||||
``arch='arm'``.
|
||||
|
||||
Examples:
|
||||
|
||||
.. doctest::
|
||||
|
||||
>>> asm("mov eax, SYS_select", arch = 'i386', os = 'freebsd')
|
||||
'\xb8]\x00\x00\x00'
|
||||
>>> asm("mov eax, SYS_select", arch = 'amd64', os = 'linux')
|
||||
'\xb8\x17\x00\x00\x00'
|
||||
>>> asm("mov rax, SYS_select", arch = 'amd64', os = 'linux')
|
||||
'H\xc7\xc0\x17\x00\x00\x00'
|
||||
>>> asm("mov r0, #SYS_select", arch = 'arm', os = 'linux', bits=32)
|
||||
'R\x00\xa0\xe3'
|
||||
>>> asm("mov eax, SYS_select", arch = 'i386', os = 'freebsd')
|
||||
'\xb8]\x00\x00\x00'
|
||||
>>> asm("mov eax, SYS_select", arch = 'amd64', os = 'linux')
|
||||
'\xb8\x17\x00\x00\x00'
|
||||
>>> asm("mov rax, SYS_select", arch = 'amd64', os = 'linux')
|
||||
'H\xc7\xc0\x17\x00\x00\x00'
|
||||
>>> asm("mov r0, #SYS_select", arch = 'arm', os = 'linux', bits=32)
|
||||
'R\x00\xa0\xe3'
|
||||
"""
|
||||
result = ''
|
||||
|
||||
@@ -562,11 +670,20 @@ def asm(shellcode, vma = 0, extract = True, shared = False):
|
||||
ldflags = ['-z', 'execstack', '-o', step3, step2]
|
||||
if vma:
|
||||
ldflags += ['--section-start=.shellcode=%#x' % vma,
|
||||
'--entry=%#x' % vma,
|
||||
'-z', 'max-page-size=4096',
|
||||
'-z', 'common-page-size=4096']
|
||||
'--entry=%#x' % vma]
|
||||
elif shared:
|
||||
ldflags += ['-shared', '-init=_start']
|
||||
|
||||
# In order to ensure that we generate ELF files with 4k pages,
|
||||
# and not e.g. 65KB pages (AArch64), force the page size.
|
||||
# This is a result of GNU Gold being silly.
|
||||
#
|
||||
# Introduced in commit dd58f409 without supporting evidence,
|
||||
# this shouldn't do anything except keep consistent page granularity
|
||||
# across architectures.
|
||||
ldflags += ['-z', 'max-page-size=4096',
|
||||
'-z', 'common-page-size=4096']
|
||||
|
||||
_run(linker + ldflags)
|
||||
|
||||
elif file(step2,'rb').read(4) == '\x7fELF':
|
||||
@@ -618,24 +735,21 @@ def disasm(data, vma = 0, byte = True, offset = True, instructions = True):
|
||||
|
||||
Examples:
|
||||
|
||||
.. doctest::
|
||||
|
||||
>>> print disasm('b85d000000'.decode('hex'), arch = 'i386')
|
||||
0: b8 5d 00 00 00 mov eax,0x5d
|
||||
>>> print disasm('b85d000000'.decode('hex'), arch = 'i386', byte = 0)
|
||||
0: mov eax,0x5d
|
||||
>>> print disasm('b85d000000'.decode('hex'), arch = 'i386', byte = 0, offset = 0)
|
||||
mov eax,0x5d
|
||||
>>> print disasm('b817000000'.decode('hex'), arch = 'amd64')
|
||||
0: b8 17 00 00 00 mov eax,0x17
|
||||
>>> print disasm('48c7c017000000'.decode('hex'), arch = 'amd64')
|
||||
0: 48 c7 c0 17 00 00 00 mov rax,0x17
|
||||
>>> print disasm('04001fe552009000'.decode('hex'), arch = 'arm')
|
||||
0: e51f0004 ldr r0, [pc, #-4] ; 0x4
|
||||
4: 00900052 addseq r0, r0, r2, asr r0
|
||||
>>> print disasm('4ff00500'.decode('hex'), arch = 'thumb', bits=32)
|
||||
0: f04f 0005 mov.w r0, #5
|
||||
>>>
|
||||
>>> print disasm('b85d000000'.decode('hex'), arch = 'i386')
|
||||
0: b8 5d 00 00 00 mov eax,0x5d
|
||||
>>> print disasm('b85d000000'.decode('hex'), arch = 'i386', byte = 0)
|
||||
0: mov eax,0x5d
|
||||
>>> print disasm('b85d000000'.decode('hex'), arch = 'i386', byte = 0, offset = 0)
|
||||
mov eax,0x5d
|
||||
>>> print disasm('b817000000'.decode('hex'), arch = 'amd64')
|
||||
0: b8 17 00 00 00 mov eax,0x17
|
||||
>>> print disasm('48c7c017000000'.decode('hex'), arch = 'amd64')
|
||||
0: 48 c7 c0 17 00 00 00 mov rax,0x17
|
||||
>>> print disasm('04001fe552009000'.decode('hex'), arch = 'arm')
|
||||
0: e51f0004 ldr r0, [pc, #-4] ; 0x4
|
||||
4: 00900052 addseq r0, r0, r2, asr r0
|
||||
>>> print disasm('4ff00500'.decode('hex'), arch = 'thumb', bits=32)
|
||||
0: f04f 0005 mov.w r0, #5
|
||||
"""
|
||||
result = ''
|
||||
|
||||
|
||||
@@ -2,12 +2,13 @@
|
||||
Analogous to atexit, this module allows the programmer to register functions to
|
||||
be run if an unhandled exception occurs.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import sys
|
||||
import threading
|
||||
import traceback
|
||||
|
||||
from .context import context
|
||||
from pwnlib.context import context
|
||||
|
||||
__all__ = ['register', 'unregister']
|
||||
|
||||
|
||||
+2
-1
@@ -7,12 +7,13 @@ this replacement module also defines :func:`unregister`.
|
||||
This module also fixes a the issue that exceptions raised by an exit handler is
|
||||
printed twice when the standard :mod:`atexit` is used.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import sys
|
||||
import threading
|
||||
import traceback
|
||||
|
||||
from .context import context
|
||||
from pwnlib.context import context
|
||||
|
||||
__all__ = ['register', 'unregister']
|
||||
|
||||
|
||||
@@ -1 +1,20 @@
|
||||
# empty
|
||||
#!/usr/bin/env python2
|
||||
__all__ = [
|
||||
'asm',
|
||||
'checksec',
|
||||
'common',
|
||||
'constgrep',
|
||||
'cyclic',
|
||||
'disasm',
|
||||
'elfdiff',
|
||||
'elfpatch',
|
||||
'errno',
|
||||
'hex',
|
||||
'main',
|
||||
'phd',
|
||||
'pwnstrip',
|
||||
'scramble',
|
||||
'shellcraft',
|
||||
'unhex',
|
||||
'update'
|
||||
]
|
||||
@@ -1,13 +1,15 @@
|
||||
#!/usr/bin/env python2
|
||||
from __future__ import absolute_import
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
from pwn import *
|
||||
from pwnlib.commandline import common
|
||||
|
||||
from . import common
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description = 'Assemble shellcode into bytes'
|
||||
parser = common.parser_commands.add_parser(
|
||||
'asm',
|
||||
help = 'Assemble shellcode into bytes'
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
@@ -91,8 +93,7 @@ parser.add_argument(
|
||||
action='store_true'
|
||||
)
|
||||
|
||||
def main():
|
||||
args = parser.parse_args()
|
||||
def main(args):
|
||||
tty = args.output.isatty()
|
||||
|
||||
data = '\n'.join(args.lines) or args.infile.read()
|
||||
@@ -123,4 +124,5 @@ def main():
|
||||
if tty and fmt is not 'raw':
|
||||
args.output.write('\n')
|
||||
|
||||
if __name__ == '__main__': main()
|
||||
if __name__ == '__main__':
|
||||
pwnlib.common.main(__file__)
|
||||
@@ -1,16 +1,16 @@
|
||||
#!/usr/bin/env python2
|
||||
from __future__ import absolute_import
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
from pwn import *
|
||||
from pwnlib.commandline import common
|
||||
|
||||
from . import common
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description = 'Check binary security settings'
|
||||
parser = common.parser_commands.add_parser(
|
||||
'checksec',
|
||||
help = 'Check binary security settings'
|
||||
)
|
||||
|
||||
|
||||
parser.add_argument(
|
||||
'elf',
|
||||
nargs='*',
|
||||
@@ -26,8 +26,7 @@ parser.add_argument(
|
||||
help='File to check (for compatibility with checksec.sh)'
|
||||
)
|
||||
|
||||
def main():
|
||||
args = parser.parse_args()
|
||||
def main(args):
|
||||
files = args.elf or args.elf2 or []
|
||||
|
||||
if not files:
|
||||
@@ -37,4 +36,5 @@ def main():
|
||||
for f in files:
|
||||
e = ELF(f.name)
|
||||
|
||||
if __name__ == '__main__': main()
|
||||
if __name__ == '__main__':
|
||||
pwnlib.common.main(__file__)
|
||||
@@ -1,10 +1,10 @@
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
|
||||
import pwnlib
|
||||
from pwnlib.context import context
|
||||
|
||||
pwnlib.log.console.stream = sys.stderr
|
||||
|
||||
choices = map(str, [16,32,64])
|
||||
choices += list(context.oses)
|
||||
choices += list(context.architectures)
|
||||
@@ -20,3 +20,13 @@ def context_arg(arg):
|
||||
try: context.endian = arg
|
||||
except Exception: pass
|
||||
return arg
|
||||
|
||||
parser = argparse.ArgumentParser(description='Pwntools Command-line Interface',
|
||||
prog='pwn')
|
||||
parser_commands = parser.add_subparsers(dest='command')
|
||||
|
||||
def main(file=sys.argv[0]):
|
||||
import pwnlib.commandline.main
|
||||
name = os.path.splitext(os.path.basename(file))[0]
|
||||
sys.argv.insert(1, name)
|
||||
pwnlib.commandline.main.main()
|
||||
@@ -1,14 +1,19 @@
|
||||
#!/usr/bin/env python2
|
||||
from __future__ import absolute_import
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
|
||||
from pwn import *
|
||||
from . import common
|
||||
import pwnlib
|
||||
pwnlib.args.free_form = False
|
||||
|
||||
p = argparse.ArgumentParser(
|
||||
description = "Looking up constants from header files.\n\nExample: constgrep -c freebsd -m ^PROT_ '3 + 4'",
|
||||
from pwn import *
|
||||
from pwnlib.commandline import common
|
||||
|
||||
p = common.parser_commands.add_parser(
|
||||
'constgrep',
|
||||
help = "Looking up constants from header files.\n\nExample: constgrep -c freebsd -m ^PROT_ '3 + 4'",
|
||||
formatter_class = argparse.RawDescriptionHelpFormatter,
|
||||
)
|
||||
|
||||
@@ -55,9 +60,7 @@ p.add_argument(
|
||||
help = 'The os/architecture/endianness/bits the shellcode will run in (default: linux/i386), choose from: %s' % common.choices,
|
||||
)
|
||||
|
||||
def main():
|
||||
args = p.parse_args()
|
||||
|
||||
def main(args):
|
||||
if args.exact:
|
||||
# This is the simple case
|
||||
print cpp(args.exact).strip()
|
||||
@@ -75,6 +78,7 @@ def main():
|
||||
else:
|
||||
matcher = re.compile(args.regex)
|
||||
|
||||
|
||||
# Evaluate the given constant
|
||||
if args.constant:
|
||||
try:
|
||||
@@ -134,4 +138,5 @@ def main():
|
||||
print
|
||||
print '(%s) == %s' % (' | '.join(k for v, k in good), args.constant)
|
||||
|
||||
if __name__ == '__main__': main()
|
||||
if __name__ == '__main__':
|
||||
pwnlib.common.main(__file__)
|
||||
@@ -1,14 +1,19 @@
|
||||
#!/usr/bin/env python2
|
||||
from __future__ import absolute_import
|
||||
|
||||
import argparse
|
||||
import string
|
||||
import sys
|
||||
|
||||
import pwnlib
|
||||
pwnlib.args.free_form = False
|
||||
|
||||
from pwn import *
|
||||
from pwnlib.commandline import common
|
||||
|
||||
from . import common
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description = "Cyclic pattern creator/finder"
|
||||
parser = common.parser_commands.add_parser(
|
||||
'cyclic',
|
||||
help = "Cyclic pattern creator/finder"
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
@@ -50,8 +55,7 @@ group.add_argument(
|
||||
help = 'Number of characters to print'
|
||||
)
|
||||
|
||||
def main():
|
||||
args = parser.parse_args()
|
||||
def main(args):
|
||||
alphabet = args.alphabet
|
||||
subsize = args.length
|
||||
|
||||
@@ -90,4 +94,5 @@ def main():
|
||||
if sys.stdout.isatty():
|
||||
sys.stdout.write('\n')
|
||||
|
||||
if __name__ == '__main__': main()
|
||||
if __name__ == '__main__':
|
||||
pwnlib.common.main(__file__)
|
||||
@@ -1,14 +1,19 @@
|
||||
#!/usr/bin/env python2
|
||||
from __future__ import absolute_import
|
||||
|
||||
import argparse
|
||||
import string
|
||||
import sys
|
||||
|
||||
import pwnlib
|
||||
pwnlib.args.free_form = False
|
||||
|
||||
from pwn import *
|
||||
from pwnlib.commandline import common
|
||||
|
||||
from . import common
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description = 'Disassemble bytes into text format'
|
||||
parser = common.parser_commands.add_parser(
|
||||
'disasm',
|
||||
help = 'Disassemble bytes into text format'
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
@@ -52,9 +57,7 @@ parser.add_argument(
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
args = parser.parse_args()
|
||||
|
||||
def main(args):
|
||||
if len(args.hex) > 0:
|
||||
dat = ''.join(args.hex)
|
||||
dat = dat.translate(None, string.whitespace)
|
||||
@@ -88,4 +91,5 @@ def main():
|
||||
|
||||
print disasm(dat, vma=safeeval.const(args.address))
|
||||
|
||||
if __name__ == '__main__': main()
|
||||
if __name__ == '__main__':
|
||||
pwnlib.common.main(__file__)
|
||||
@@ -1,12 +1,18 @@
|
||||
#!/usr/bin/env python2
|
||||
import shutil
|
||||
from __future__ import absolute_import
|
||||
|
||||
import shutil
|
||||
from argparse import ArgumentParser
|
||||
from subprocess import CalledProcessError
|
||||
from subprocess import check_output
|
||||
from tempfile import NamedTemporaryFile
|
||||
|
||||
import pwnlib
|
||||
pwnlib.args.free_form = False
|
||||
|
||||
from pwn import *
|
||||
from pwnlib.commandline import common
|
||||
|
||||
|
||||
def dump(objdump, path):
|
||||
n = NamedTemporaryFile(delete=False)
|
||||
@@ -20,13 +26,15 @@ def diff(a,b):
|
||||
except CalledProcessError as e:
|
||||
return e.output
|
||||
|
||||
p = ArgumentParser()
|
||||
p = common.parser_commands.add_parser(
|
||||
'elfdiff',
|
||||
help = 'Compare two ELF files'
|
||||
)
|
||||
|
||||
p.add_argument('a')
|
||||
p.add_argument('b')
|
||||
|
||||
def main():
|
||||
a = p.parse_args()
|
||||
|
||||
def main(a):
|
||||
with context.silent:
|
||||
x = ELF(a.a)
|
||||
y = ELF(a.b)
|
||||
@@ -49,4 +57,5 @@ def main():
|
||||
|
||||
print diff(x, y)
|
||||
|
||||
if __name__ == '__main__': main()
|
||||
if __name__ == '__main__':
|
||||
pwnlib.common.main(__file__)
|
||||
@@ -1,8 +1,19 @@
|
||||
#!/usr/bin/env python2
|
||||
from __future__ import absolute_import
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
import pwnlib
|
||||
pwnlib.args.free_form = False
|
||||
|
||||
from pwn import *
|
||||
from pwnlib.commandline import common
|
||||
|
||||
p = common.parser_commands.add_parser(
|
||||
'elfpatch',
|
||||
help = 'Patch an ELF file'
|
||||
)
|
||||
|
||||
p = argparse.ArgumentParser()
|
||||
p.add_argument('elf',help="File to patch")
|
||||
@@ -10,9 +21,7 @@ p.add_argument('offset',help="Offset to patch in virtual address (hex encoded)")
|
||||
p.add_argument('bytes',help='Bytes to patch (hex encoded)')
|
||||
|
||||
|
||||
def main():
|
||||
a = p.parse_args()
|
||||
|
||||
def main(a):
|
||||
if not a.offset.startswith('0x'):
|
||||
a.offset = '0x' + a.offset
|
||||
|
||||
@@ -25,4 +34,5 @@ def main():
|
||||
elf.write(offset, bytes)
|
||||
sys.stdout.write(elf.get_data())
|
||||
|
||||
if __name__ == '__main__': main()
|
||||
if __name__ == '__main__':
|
||||
pwnlib.common.main(__file__)
|
||||
@@ -1,17 +1,20 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import argparse
|
||||
import os
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description = 'Prints out error messages'
|
||||
from pwnlib.commandline import common
|
||||
|
||||
parser = common.parser_commands.add_parser(
|
||||
'errno',
|
||||
help = 'Prints out error messages'
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
'error', help='Error message or value', type=str
|
||||
)
|
||||
|
||||
def main():
|
||||
args, unknown = parser.parse_known_args()
|
||||
|
||||
def main(args):
|
||||
try:
|
||||
value = int(args.error, 0)
|
||||
|
||||
@@ -40,4 +43,5 @@ def main():
|
||||
print '#define', name, value
|
||||
print os.strerror(value)
|
||||
|
||||
if __name__ == '__main__': main()
|
||||
if __name__ == '__main__':
|
||||
pwnlib.common.main(__file__)
|
||||
@@ -1,18 +1,24 @@
|
||||
#!/usr/bin/env python2
|
||||
from __future__ import absolute_import
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
parser = argparse.ArgumentParser(description='''
|
||||
Hex-encodes data provided on the command line or via stdin.
|
||||
from pwnlib.commandline import common
|
||||
|
||||
parser = common.parser_commands.add_parser(
|
||||
'hex',
|
||||
help = '''
|
||||
Hex-encodes data provided on the command line or stdin
|
||||
''')
|
||||
parser.add_argument('data', nargs='*',
|
||||
help='Data to convert into hex')
|
||||
|
||||
def main():
|
||||
args = parser.parse_args()
|
||||
def main(args):
|
||||
if not args.data:
|
||||
print sys.stdin.read().encode('hex')
|
||||
else:
|
||||
print ' '.join(args.data).encode('hex')
|
||||
|
||||
if __name__ == '__main__': main()
|
||||
if __name__ == '__main__':
|
||||
pwnlib.common.main(__file__)
|
||||
@@ -0,0 +1,48 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import sys
|
||||
|
||||
from pwnlib.commandline import asm
|
||||
from pwnlib.commandline import checksec
|
||||
from pwnlib.commandline import common
|
||||
from pwnlib.commandline import constgrep
|
||||
from pwnlib.commandline import cyclic
|
||||
from pwnlib.commandline import disasm
|
||||
from pwnlib.commandline import elfdiff
|
||||
from pwnlib.commandline import elfpatch
|
||||
from pwnlib.commandline import errno
|
||||
from pwnlib.commandline import hex
|
||||
from pwnlib.commandline import phd
|
||||
from pwnlib.commandline import pwnstrip
|
||||
from pwnlib.commandline import scramble
|
||||
from pwnlib.commandline import shellcraft
|
||||
from pwnlib.commandline import unhex
|
||||
from pwnlib.commandline import update
|
||||
from pwnlib.commandline.common import parser
|
||||
from pwnlib.context import context
|
||||
|
||||
commands = {
|
||||
'asm': asm.main,
|
||||
'checksec': checksec.main,
|
||||
'constgrep': constgrep.main,
|
||||
'cyclic': cyclic.main,
|
||||
'disasm': disasm.main,
|
||||
'elfdiff': elfdiff.main,
|
||||
'elfpatch': elfpatch.main,
|
||||
'errno': errno.main,
|
||||
'hex': hex.main,
|
||||
'phd': phd.main,
|
||||
'pwnstrip': pwnstrip.main,
|
||||
'scramble': scramble.main,
|
||||
'shellcraft': shellcraft.main,
|
||||
'unhex': unhex.main,
|
||||
'update': update.main,
|
||||
}
|
||||
|
||||
def main():
|
||||
args = parser.parse_args()
|
||||
with context.local(log_console = sys.stderr):
|
||||
commands[args.command](args)
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
@@ -1,12 +1,19 @@
|
||||
#!/usr/bin/env python2
|
||||
from __future__ import absolute_import
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
|
||||
from pwn import *
|
||||
import pwnlib
|
||||
pwnlib.args.free_form = False
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description = 'Pwnlib HexDump'
|
||||
from pwn import *
|
||||
from pwnlib.commandline import common
|
||||
|
||||
parser = common.parser_commands.add_parser(
|
||||
'phd',
|
||||
help = 'Pwnlib HexDump'
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
@@ -64,9 +71,7 @@ def asint(s):
|
||||
else:
|
||||
return int(s, 10)
|
||||
|
||||
def main():
|
||||
args = parser.parse_args()
|
||||
|
||||
def main(args):
|
||||
infile = args.file
|
||||
width = asint(args.width)
|
||||
skip = asint(args.skip)
|
||||
@@ -95,4 +100,5 @@ def main():
|
||||
except (KeyboardInterrupt, IOError):
|
||||
pass
|
||||
|
||||
if __name__ == '__main__': main()
|
||||
if __name__ == '__main__':
|
||||
pwnlib.common.main(__file__)
|
||||
@@ -1,12 +1,16 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import argparse
|
||||
|
||||
import pwnlib
|
||||
pwnlib.args.free_form = False
|
||||
|
||||
from pwn import *
|
||||
from pwnlib.commandline import common
|
||||
|
||||
from . import common
|
||||
|
||||
p = argparse.ArgumentParser(
|
||||
description = 'Strip binaries for CTF usage',
|
||||
formatter_class = argparse.RawDescriptionHelpFormatter,
|
||||
p = common.parser_commands.add_parser(
|
||||
'pwnstrip',
|
||||
help = 'Strip binaries for CTF usage',
|
||||
)
|
||||
|
||||
g = p.add_argument_group("actions")
|
||||
@@ -15,9 +19,7 @@ g.add_argument('-p', '--patch', metavar='FUNCTION', help="Patch function", actio
|
||||
p.add_argument('-o', '--output', type=file, default=sys.stdout)
|
||||
p.add_argument('file', type=file)
|
||||
|
||||
def main():
|
||||
args = p.parse_args()
|
||||
|
||||
def main(args):
|
||||
if not (args.patch or args.build_id):
|
||||
sys.stderr.write("Must specify at least one action\n")
|
||||
sys.stderr.write(p.format_usage())
|
||||
@@ -48,6 +50,5 @@ def main():
|
||||
|
||||
args.output.write(result)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
pwnlib.common.main(__file__)
|
||||
@@ -1,15 +1,19 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
|
||||
import pwnlib
|
||||
pwnlib.args.free_form = False
|
||||
|
||||
from pwn import *
|
||||
from pwnlib.commandline import common
|
||||
|
||||
from . import common
|
||||
|
||||
parser = argparse.ArgumentParser(
|
||||
description = 'Shellcode encoder'
|
||||
parser = common.parser_commands.add_parser(
|
||||
'scramble',
|
||||
help = 'Shellcode encoder'
|
||||
)
|
||||
|
||||
|
||||
parser.add_argument(
|
||||
"-f", "--format",
|
||||
help="Output format (defaults to hex for ttys, otherwise raw)",
|
||||
@@ -68,8 +72,7 @@ parser.add_argument(
|
||||
action='store_true'
|
||||
)
|
||||
|
||||
def main():
|
||||
args = parser.parse_args()
|
||||
def main(args):
|
||||
tty = args.output.isatty()
|
||||
|
||||
if sys.stdin.isatty():
|
||||
@@ -100,4 +103,6 @@ def main():
|
||||
if tty and fmt is not 'raw':
|
||||
args.output.write('\n')
|
||||
|
||||
if __name__ == '__main__': main()
|
||||
|
||||
if __name__ == '__main__':
|
||||
pwnlib.common.main(__file__)
|
||||
@@ -1,24 +1,16 @@
|
||||
#!/usr/bin/env python2
|
||||
from __future__ import absolute_import
|
||||
|
||||
import argparse
|
||||
import os
|
||||
import sys
|
||||
import types
|
||||
|
||||
import pwnlib
|
||||
pwnlib.args.free_form = False
|
||||
|
||||
from pwn import *
|
||||
|
||||
from . import common
|
||||
|
||||
r = text.red
|
||||
g = text.green
|
||||
b = text.blue
|
||||
|
||||
banner = '\n'.join([' ' + r('____') + ' ' + g('_') + ' ' + r('_') + ' ' + g('_') + ' ' + b('__') + ' ' + r('_'),
|
||||
' ' + r('/ ___|') + g('| |__') + ' ' + b('___') + r('| |') + ' ' + g('|') + ' ' + b('___') + ' ' + r('_ __') + ' ' + g('__ _') + ' ' + b('/ _|') + ' ' + r('|_'),
|
||||
' ' + r('\___ \\') + g('| \'_ \\') + ' ' + b('/ _ \\') + ' ' + r('|') + ' ' + g('|') + b('/ __|') + ' ' + r('\'__/') + ' ' + g('_` |') + ' ' + b('|_') + r('| __|'),
|
||||
' ' + r('___) |') + ' ' + g('| | |') + ' ' + b('__/') + ' ' + r('|') + ' ' + g('|') + ' ' + b('(__') + r('| |') + ' ' + g('| (_| |') + ' ' + b('_|') + ' ' + r('|_'),
|
||||
' ' + r('|____/') + g('|_| |_|') + b('\\___|') + r('_|') + g('_|') + b('\\___|') + r('_|') + ' ' + g('\\__,_|') + b('_|') + ' ' + r('\\__|'),
|
||||
'\n'
|
||||
])
|
||||
from pwnlib.commandline import common
|
||||
|
||||
|
||||
# ____ _ _ _ __ _
|
||||
@@ -37,9 +29,10 @@ def _string(s):
|
||||
out.append('\\x%02x' % co)
|
||||
return '"' + ''.join(out) + '"\n'
|
||||
|
||||
p = argparse.ArgumentParser(
|
||||
description = 'Microwave shellcode -- Easy, fast and delicious',
|
||||
formatter_class = argparse.RawDescriptionHelpFormatter,
|
||||
|
||||
p = common.parser_commands.add_parser(
|
||||
'shellcraft',
|
||||
help = 'Microwave shellcode -- Easy, fast and delicious',
|
||||
)
|
||||
|
||||
|
||||
@@ -68,21 +61,19 @@ p.add_argument(
|
||||
'p',
|
||||
'i', 'hexii',
|
||||
'e', 'elf',
|
||||
'd', 'escaped',
|
||||
'default'],
|
||||
default = 'default',
|
||||
help = 'Output format (default: hex), choose from {r}aw, {s}tring, {c}-style array, {h}ex string, hex{i}i, {a}ssembly code, {p}reprocssed code',
|
||||
help = 'Output format (default: hex), choose from {e}lf, {r}aw, {s}tring, {c}-style array, {h}ex string, hex{i}i, {a}ssembly code, {p}reprocssed code, escape{d} hex string',
|
||||
)
|
||||
|
||||
p.add_argument(
|
||||
'shellcode',
|
||||
nargs = '?',
|
||||
choices = shellcraft.templates,
|
||||
metavar = 'shellcode',
|
||||
help = 'The shellcode you want',
|
||||
type = str
|
||||
)
|
||||
|
||||
p.epilog = 'Available shellcodes are:\n' + '\n'.join(shellcraft.templates)
|
||||
|
||||
p.add_argument(
|
||||
'args',
|
||||
nargs = '*',
|
||||
@@ -167,6 +158,12 @@ p.add_argument(
|
||||
default=None
|
||||
)
|
||||
|
||||
p.add_argument(
|
||||
'-l', '--list',
|
||||
action='store_true',
|
||||
help='List available shellcodes, optionally provide a filter'
|
||||
)
|
||||
|
||||
def get_template(name):
|
||||
func = shellcraft
|
||||
for attr in name.split('.'):
|
||||
@@ -175,23 +172,27 @@ def get_template(name):
|
||||
|
||||
def is_not_a_syscall_template(name):
|
||||
template_src = shellcraft._get_source(name)
|
||||
return 'man 2' not in read(template_src)
|
||||
return '/syscalls' not in template_src
|
||||
|
||||
def main():
|
||||
# Banner must be added here so that it doesn't appear in the autodoc
|
||||
# generation for command line tools
|
||||
p.description = banner + p.description
|
||||
args = p.parse_args()
|
||||
|
||||
if not args.shellcode:
|
||||
def main(args):
|
||||
if args.list:
|
||||
templates = shellcraft.templates
|
||||
|
||||
if not args.syscalls:
|
||||
if args.shellcode:
|
||||
templates = filter(lambda a: args.shellcode in a, templates)
|
||||
elif not args.syscalls:
|
||||
templates = filter(is_not_a_syscall_template, templates)
|
||||
|
||||
print '\n'.join(templates)
|
||||
exit()
|
||||
|
||||
if not args.shellcode:
|
||||
common.parser.print_usage()
|
||||
exit()
|
||||
|
||||
if args.shellcode not in shellcraft.templates:
|
||||
log.error("Unknown shellcraft template %r. Use --list to see available shellcodes." % args.shellcode)
|
||||
|
||||
func = get_template(args.shellcode)
|
||||
|
||||
if args.show:
|
||||
@@ -326,17 +327,19 @@ def main():
|
||||
sys.exit(0)
|
||||
|
||||
if args.format in ['s', 'str', 'string']:
|
||||
code = _string(code) + '"\n'
|
||||
code = _string(code)
|
||||
elif args.format == 'c':
|
||||
code = '{' + ', '.join(map(hex, bytearray(code))) + '}' + '\n'
|
||||
elif args.format in ['h', 'hex']:
|
||||
code = pwnlib.util.fiddling.enhex(code) + '\n'
|
||||
elif args.format in ['i', 'hexii']:
|
||||
code = hexii(code) + '\n'
|
||||
|
||||
elif args.format in ['d', 'escaped']:
|
||||
code = ''.join('\\x%02x' % ord(c) for c in code) + '\n'
|
||||
if not sys.stdin.isatty():
|
||||
args.out.write(sys.stdin.read())
|
||||
|
||||
args.out.write(code)
|
||||
|
||||
if __name__ == '__main__': main()
|
||||
if __name__ == '__main__':
|
||||
pwnlib.common.main(__file__)
|
||||
@@ -1,23 +1,30 @@
|
||||
#!/usr/bin/env python2
|
||||
from __future__ import absolute_import
|
||||
|
||||
import argparse
|
||||
import sys
|
||||
from string import whitespace
|
||||
|
||||
parser = argparse.ArgumentParser(description='''
|
||||
from pwnlib.commandline import common
|
||||
|
||||
parser = common.parser_commands.add_parser(
|
||||
'unhex',
|
||||
help = '''
|
||||
Decodes hex-encoded data provided on the command line or via stdin.
|
||||
''')
|
||||
|
||||
parser.add_argument('hex', nargs='*',
|
||||
help='Hex bytes to decode')
|
||||
|
||||
def main():
|
||||
args = parser.parse_args()
|
||||
def main(args):
|
||||
try:
|
||||
if not args.hex:
|
||||
s = sys.stdin.read().translate(None, whitespace)
|
||||
sys.stdout.write(s.decode('hex'))
|
||||
else:
|
||||
sys.stdout.write(''.join(sys.argv[1:]).decode('hex'))
|
||||
sys.stdout.write(''.join(args.hex).decode('hex'))
|
||||
except TypeError, e:
|
||||
sys.stderr.write(str(e) + '\n')
|
||||
|
||||
if __name__ == '__main__': main()
|
||||
if __name__ == '__main__':
|
||||
pwnlib.common.main(__file__)
|
||||
@@ -0,0 +1,31 @@
|
||||
#!/usr/bin/env python2
|
||||
from __future__ import absolute_import
|
||||
|
||||
import subprocess
|
||||
|
||||
import pwnlib
|
||||
pwnlib.args.free_form = False
|
||||
|
||||
from pwn import *
|
||||
from pwnlib.commandline import common
|
||||
|
||||
p = common.parser_commands.add_parser(
|
||||
'update',
|
||||
help = 'Check for pwntools updates'
|
||||
)
|
||||
|
||||
p.add_argument('--install', action='store_true', help='''
|
||||
Install the update automatically.
|
||||
''')
|
||||
|
||||
p.add_argument('--pre', action='store_true', help='''
|
||||
Check for pre-releases.
|
||||
''')
|
||||
|
||||
def main(a):
|
||||
result = pwnlib.update.perform_check(prerelease=a.pre)
|
||||
if a.install:
|
||||
subprocess.check_call(result, shell=False)
|
||||
|
||||
if __name__ == '__main__':
|
||||
pwnlib.common.main(__file__)
|
||||
@@ -40,13 +40,15 @@ Example:
|
||||
4
|
||||
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import importlib
|
||||
import sys
|
||||
from types import ModuleType
|
||||
|
||||
from ..context import context
|
||||
from ..util import safeeval
|
||||
from .constant import Constant
|
||||
from pwnlib.constants.constant import Constant
|
||||
from pwnlib.context import context
|
||||
from pwnlib.util import safeeval
|
||||
|
||||
|
||||
class ConstantsModule(ModuleType):
|
||||
@@ -137,6 +139,11 @@ class ConstantsModule(ModuleType):
|
||||
if not isinstance(string, str):
|
||||
return string
|
||||
|
||||
simple = getattr(self, string, None)
|
||||
|
||||
if simple is not None:
|
||||
return simple
|
||||
|
||||
key = context.os, context.arch
|
||||
if key not in self._env_store:
|
||||
self._env_store[key] = {key: getattr(self, key) for key in dir(self) if not key.endswith('__')}
|
||||
|
||||
+133
-13
@@ -4,12 +4,15 @@
|
||||
Implements context management so that nested/scoped contexts and threaded
|
||||
contexts work properly and as expected.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import collections
|
||||
import functools
|
||||
import logging
|
||||
import os
|
||||
import platform
|
||||
import socket
|
||||
import stat
|
||||
import string
|
||||
import subprocess
|
||||
import sys
|
||||
@@ -18,8 +21,8 @@ import time
|
||||
|
||||
import socks
|
||||
|
||||
from ..device import Device
|
||||
from ..timeout import Timeout
|
||||
from pwnlib.device import Device
|
||||
from pwnlib.timeout import Timeout
|
||||
|
||||
_original_socket = socket.socket
|
||||
|
||||
@@ -260,7 +263,7 @@ class ContextType(object):
|
||||
r"""
|
||||
Class for specifying information about the target machine.
|
||||
Intended for use as a pseudo-singleton through the global
|
||||
variable ``pwnlib.context.context``, available via
|
||||
variable :data:`.context`, available via
|
||||
``from pwn import *`` as ``context``.
|
||||
|
||||
The context is usually specified at the top of the Python file for clarity. ::
|
||||
@@ -329,12 +332,16 @@ class ContextType(object):
|
||||
'aslr': True,
|
||||
'binary': None,
|
||||
'bits': 32,
|
||||
'buffer_size': 4096,
|
||||
'delete_corefiles': False,
|
||||
'device': os.getenv('ANDROID_SERIAL', None) or None,
|
||||
'endian': 'little',
|
||||
'kernel': None,
|
||||
'log_level': logging.INFO,
|
||||
'log_file': _devnull(),
|
||||
'log_console': sys.stdout,
|
||||
'randomize': False,
|
||||
'rename_corefiles': True,
|
||||
'newline': '\n',
|
||||
'noptrace': False,
|
||||
'os': 'linux',
|
||||
@@ -530,6 +537,18 @@ class ContextType(object):
|
||||
level = None
|
||||
return self.local(function, log_level=level)
|
||||
|
||||
def quietfunc(self, function):
|
||||
"""Similar to :attr:`quiet`, but wraps a whole function."""
|
||||
@functools.wraps(function)
|
||||
def wrapper(*a, **kw):
|
||||
level = 'error'
|
||||
if context.log_level <= logging.DEBUG:
|
||||
level = None
|
||||
with self.local(function, log_level=level):
|
||||
return function(*a, **kw)
|
||||
return wrapper
|
||||
|
||||
|
||||
@property
|
||||
def verbose(self):
|
||||
"""Enable all logging within the enclosed scope.
|
||||
@@ -549,6 +568,7 @@ class ContextType(object):
|
||||
Examples:
|
||||
|
||||
>>> # Default value
|
||||
>>> context.clear()
|
||||
>>> context.arch == 'i386'
|
||||
True
|
||||
>>> context.arch = 'arm'
|
||||
@@ -675,7 +695,7 @@ class ContextType(object):
|
||||
"""
|
||||
ASLR settings for new processes.
|
||||
|
||||
If ``False``, attempt to disable ASLR in all processes which are
|
||||
If :const:`False`, attempt to disable ASLR in all processes which are
|
||||
created via ``personality`` (``setarch -R``) and ``setrlimit``
|
||||
(``ulimit -s unlimited``).
|
||||
|
||||
@@ -742,7 +762,7 @@ class ContextType(object):
|
||||
|
||||
"""
|
||||
# Cyclic imports... sorry Idolf.
|
||||
from ..elf import ELF
|
||||
from pwnlib.elf import ELF
|
||||
|
||||
if not isinstance(binary, ELF):
|
||||
binary = ELF(binary)
|
||||
@@ -911,6 +931,24 @@ class ContextType(object):
|
||||
value.flush()
|
||||
return value
|
||||
|
||||
@_validator
|
||||
def log_console(self, stream):
|
||||
"""
|
||||
Sets the default logging console target.
|
||||
|
||||
Examples:
|
||||
|
||||
>>> context.log_level = 'warn'
|
||||
>>> log.warn("Hello")
|
||||
[!] Hello
|
||||
>>> context.log_console=open('/dev/null', 'w')
|
||||
>>> log.warn("Hello")
|
||||
>>> context.clear()
|
||||
"""
|
||||
if isinstance(stream, str):
|
||||
stream = open(stream, 'wt')
|
||||
return stream
|
||||
|
||||
@property
|
||||
def mask(self):
|
||||
return (1 << self.bits) - 1
|
||||
@@ -953,7 +991,7 @@ class ContextType(object):
|
||||
|
||||
Can be set to any non-string truthy value, or the specific string
|
||||
values ``'signed'`` or ``'unsigned'`` which are converted into
|
||||
``True`` and ``False`` correspondingly.
|
||||
:const:`True` and :const:`False` correspondingly.
|
||||
|
||||
Examples:
|
||||
|
||||
@@ -1086,17 +1124,23 @@ class ContextType(object):
|
||||
self.arch = device.arch or self.arch
|
||||
self.bits = device.bits or self.bits
|
||||
self.endian = device.endian or self.endian
|
||||
self.os = device.os or self.os
|
||||
elif isinstance(device, str):
|
||||
device = Device(device)
|
||||
else:
|
||||
elif device is not None:
|
||||
raise AttributeError("device must be either a Device object or a serial number as a string")
|
||||
|
||||
return device
|
||||
|
||||
@property
|
||||
def adb(self):
|
||||
"""Returns an argument array for connecting to adb."""
|
||||
command = ['adb']
|
||||
"""Returns an argument array for connecting to adb.
|
||||
|
||||
Unless ``$ADB_PATH`` is set, uses the default ``adb`` binary in ``$PATH``.
|
||||
"""
|
||||
ADB_PATH = os.environ.get('ADB_PATH', 'adb')
|
||||
|
||||
command = [ADB_PATH]
|
||||
|
||||
if self.adb_host != self.defaults['adb_host']:
|
||||
command += ['-H', self.adb_host]
|
||||
@@ -1109,6 +1153,79 @@ class ContextType(object):
|
||||
|
||||
return command
|
||||
|
||||
@_validator
|
||||
def buffer_size(self, size):
|
||||
"""Internal buffer size to use for :class:`pwnlib.tubes.tube.tube` objects.
|
||||
|
||||
This is not the maximum size of the buffer, but this is the amount of data
|
||||
which is passed to each raw ``read`` syscall (or equivalent).
|
||||
"""
|
||||
return int(size)
|
||||
|
||||
@property
|
||||
def cache_dir(self):
|
||||
"""Directory used for caching data.
|
||||
|
||||
Note:
|
||||
May be either a path string, or :const:`None`.
|
||||
|
||||
Example:
|
||||
|
||||
>>> cache_dir = context.cache_dir
|
||||
>>> cache_dir is not None
|
||||
True
|
||||
>>> os.chmod(cache_dir, 0o000)
|
||||
>>> context.cache_dir is None
|
||||
True
|
||||
>>> os.chmod(cache_dir, 0o755)
|
||||
>>> cache_dir == context.cache_dir
|
||||
True
|
||||
"""
|
||||
home = os.path.expanduser('~')
|
||||
|
||||
if not os.access(home, os.W_OK):
|
||||
return None
|
||||
|
||||
cache = os.path.join(home, '.pwntools-cache')
|
||||
|
||||
if not os.path.exists(cache):
|
||||
try:
|
||||
os.mkdir(cache)
|
||||
except OSError:
|
||||
return None
|
||||
|
||||
# Some wargames e.g. pwnable.kr have created dummy directories
|
||||
# which cannot be modified by the user account (owned by root).
|
||||
if not os.access(cache, os.W_OK):
|
||||
return None
|
||||
|
||||
return cache
|
||||
|
||||
@_validator
|
||||
def delete_corefiles(self, v):
|
||||
"""Whether pwntools automatically deletes corefiles after exiting.
|
||||
This only affects corefiles accessed via :attr:`.process.corefile`.
|
||||
|
||||
Default value is ``False``.
|
||||
"""
|
||||
return bool(v)
|
||||
|
||||
@_validator
|
||||
def rename_corefiles(self, v):
|
||||
"""Whether pwntools automatically renames corefiles.
|
||||
|
||||
This is useful for two things:
|
||||
|
||||
- Prevent corefiles from being overwritten, if ``kernel.core_pattern``
|
||||
is something simple like ``"core"``.
|
||||
- Ensure corefiles are generated, if ``kernel.core_pattern`` uses ``apport``,
|
||||
which refuses to overwrite any existing files.
|
||||
|
||||
This only affects corefiles accessed via :attr:`.process.corefile`.
|
||||
|
||||
Default value is ``True``.
|
||||
"""
|
||||
return bool(v)
|
||||
|
||||
#*************************************************************************
|
||||
# ALIASES
|
||||
@@ -1184,11 +1301,14 @@ class ContextType(object):
|
||||
Thread = Thread
|
||||
|
||||
|
||||
#: Global ``context`` object, used to store commonly-used pwntools settings.
|
||||
#: Global :class:`.ContextType` object, used to store commonly-used pwntools settings.
|
||||
#:
|
||||
#: In most cases, the context is used to infer default variables values.
|
||||
#: For example, :meth:`pwnlib.asm.asm` can take an ``os`` parameter as a
|
||||
#: keyword argument. If it is not supplied, the ``os`` specified by
|
||||
#: ``context`` is used instead.
|
||||
#: For example, :func:`.asm` can take an ``arch`` parameter as a
|
||||
#: keyword argument.
|
||||
#:
|
||||
#: If it is not supplied, the ``arch`` specified by ``context`` is used instead.
|
||||
#:
|
||||
#: Consider it a shorthand to passing ``os=`` and ``arch=`` to every single
|
||||
#: function call.
|
||||
context = ContextType()
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
ROOT=$(shell git rev-parse --show-toplevel)
|
||||
TEMPLATE_DIR="$ROOT/pwnlib/shellcraft/templates/common/linux/syscalls"
|
||||
|
||||
all: generate.py functions.py
|
||||
python generate.py "$(ROOT)/pwnlib/shellcraft/templates/common/linux/syscalls"
|
||||
|
||||
functions.py:
|
||||
wget https://raw.githubusercontent.com/zachriggle/functions/master/functions.py
|
||||
|
||||
.phony: all
|
||||
@@ -0,0 +1,283 @@
|
||||
#!/usr/bin/env python2
|
||||
import argparse
|
||||
import os
|
||||
|
||||
from pwnlib import constants
|
||||
from pwnlib.context import context
|
||||
|
||||
# github.com/zachriggle/functions
|
||||
from functions import functions, Function, Argument
|
||||
|
||||
ARCHITECTURES = ['i386', 'amd64', 'arm', 'aarch64', 'mips']
|
||||
|
||||
HEADER = '''
|
||||
<%
|
||||
import collections
|
||||
import pwnlib.abi
|
||||
import pwnlib.constants
|
||||
import pwnlib.shellcraft
|
||||
%>
|
||||
'''
|
||||
|
||||
DOCSTRING = '''
|
||||
<%docstring>{name}({arguments_comma_separated}) -> str
|
||||
|
||||
Invokes the syscall {name}.
|
||||
|
||||
See 'man 2 {name}' for more information.
|
||||
|
||||
Arguments:
|
||||
{arg_docs}
|
||||
Returns:
|
||||
{return_type}
|
||||
</%docstring>
|
||||
'''
|
||||
|
||||
ARGUMENTS = """
|
||||
<%page args="{arguments_default_values}"/>
|
||||
"""
|
||||
|
||||
CALL = """
|
||||
<%
|
||||
abi = pwnlib.abi.ABI.syscall()
|
||||
stack = abi.stack
|
||||
regs = abi.register_arguments[1:]
|
||||
allregs = pwnlib.shellcraft.registers.current()
|
||||
|
||||
can_pushstr = {string_arguments!r}
|
||||
can_pushstr_array = {array_arguments!r}
|
||||
|
||||
argument_names = {argument_names!r}
|
||||
argument_values = [{arguments_comma_separated!s}]
|
||||
|
||||
# Load all of the arguments into their destination registers / stack slots.
|
||||
register_arguments = dict()
|
||||
stack_arguments = collections.OrderedDict()
|
||||
string_arguments = dict()
|
||||
dict_arguments = dict()
|
||||
array_arguments = dict()
|
||||
syscall_repr = []
|
||||
|
||||
for name, arg in zip(argument_names, argument_values):
|
||||
if arg is not None:
|
||||
syscall_repr.append('%s=%r' % (name, arg))
|
||||
|
||||
# If the argument itself (input) is a register...
|
||||
if arg in allregs:
|
||||
index = argument_names.index(name)
|
||||
if index < len(regs):
|
||||
target = regs[index]
|
||||
register_arguments[target] = arg
|
||||
elif arg is not None:
|
||||
stack_arguments[index] = arg
|
||||
|
||||
# The argument is not a register. It is a string value, and we
|
||||
# are expecting a string value
|
||||
elif name in can_pushstr and isinstance(arg, str):
|
||||
string_arguments[name] = arg
|
||||
|
||||
# The argument is not a register. It is a dictionary, and we are
|
||||
# expecting K:V paris.
|
||||
elif name in can_pushstr_array and isinstance(arg, dict):
|
||||
array_arguments[name] = ['%s=%s' % (k,v) for (k,v) in arg.items()]
|
||||
|
||||
# The arguent is not a register. It is a list, and we are expecting
|
||||
# a list of arguments.
|
||||
elif name in can_pushstr_array and isinstance(arg, (list, tuple)):
|
||||
array_arguments[name] = arg
|
||||
|
||||
# The argument is not a register, string, dict, or list.
|
||||
# It could be a constant string ('O_RDONLY') for an integer argument,
|
||||
# an actual integer value, or a constant.
|
||||
else:
|
||||
index = argument_names.index(name)
|
||||
if index < len(regs):
|
||||
target = regs[index]
|
||||
register_arguments[target] = arg
|
||||
elif arg is not None:
|
||||
stack_arguments[target] = arg
|
||||
|
||||
# Some syscalls have different names on various architectures.
|
||||
# Determine which syscall number to use for the current architecture.
|
||||
for syscall in {syscalls!r}:
|
||||
if hasattr(pwnlib.constants, syscall):
|
||||
break
|
||||
else:
|
||||
raise Exception("Could not locate any syscalls: %r" % syscalls)
|
||||
%>
|
||||
/* {name}(${{', '.join(syscall_repr)}}) */
|
||||
%for name, arg in string_arguments.items():
|
||||
${{pwnlib.shellcraft.pushstr(arg, append_null=('\\x00' not in arg))}}
|
||||
${{pwnlib.shellcraft.mov(regs[argument_names.index(name)], abi.stack)}}
|
||||
%endfor
|
||||
%for name, arg in array_arguments.items():
|
||||
${{pwnlib.shellcraft.pushstr_array(regs[argument_names.index(name)], arg)}}
|
||||
%endfor
|
||||
%for name, arg in stack_arguments.items():
|
||||
${{pwnlib.shellcraft.push(arg)}}
|
||||
%endfor
|
||||
${{pwnlib.shellcraft.setregs(register_arguments)}}
|
||||
${{pwnlib.shellcraft.syscall(syscall)}}
|
||||
"""
|
||||
|
||||
|
||||
def can_be_constant(arg):
|
||||
if arg.derefcnt == 0:
|
||||
return True
|
||||
|
||||
|
||||
def can_be_string(arg):
|
||||
if arg.type == 'char' and arg.derefcnt == 1:
|
||||
return True
|
||||
if arg.type == 'void' and arg.derefcnt == 1:
|
||||
return True
|
||||
|
||||
def can_be_array(arg):
|
||||
if arg.type == 'char' and arg.derefcnt == 2:
|
||||
return True
|
||||
if arg.type == 'void' and arg.derefcnt == 2:
|
||||
return True
|
||||
|
||||
|
||||
def fix_bad_arg_names(func, arg):
|
||||
if arg.name == 'str':
|
||||
return 'str_'
|
||||
if arg.name == 'len':
|
||||
return 'length'
|
||||
if arg.name == 'repr':
|
||||
return 'repr_'
|
||||
|
||||
if func.name == 'open' and arg.name == 'vararg':
|
||||
return 'mode'
|
||||
|
||||
return arg.name
|
||||
|
||||
|
||||
def get_arg_default(arg):
|
||||
return 0
|
||||
|
||||
def fix_rt_syscall_name(name):
|
||||
if name.startswith('rt_'):
|
||||
return name[3:]
|
||||
return name
|
||||
|
||||
def fix_syscall_names(name):
|
||||
# Do not use old_mmap
|
||||
if name == 'SYS_mmap':
|
||||
return ['SYS_mmap2', name]
|
||||
# Some arches don't have vanilla sigreturn
|
||||
if name.endswith('_sigreturn'):
|
||||
return ['SYS_sigreturn', 'SYS_rt_sigreturn']
|
||||
return [name]
|
||||
|
||||
|
||||
def main(target):
|
||||
for arch in ARCHITECTURES:
|
||||
with context.local(arch=arch):
|
||||
generate_one(target)
|
||||
|
||||
def generate_one(target):
|
||||
SYSCALL_NAMES = [c for c in dir(constants) if c.startswith('SYS_')]
|
||||
|
||||
for syscall in SYSCALL_NAMES:
|
||||
name = syscall[4:]
|
||||
|
||||
# Skip anything with uppercase
|
||||
if name.lower() != name:
|
||||
print 'Skipping %s' % name
|
||||
continue
|
||||
|
||||
# Skip anything that starts with 'unused' or 'sys' after stripping
|
||||
if name.startswith('unused'):
|
||||
print 'Skipping %s' % name
|
||||
continue
|
||||
|
||||
function = functions.get(name, None)
|
||||
|
||||
if name.startswith('rt_'):
|
||||
name = name[3:]
|
||||
|
||||
# If we can't find a function, just stub it out with something
|
||||
# that has a vararg argument.
|
||||
if function is None:
|
||||
print 'Stubbing out %s' % name
|
||||
args = [Argument('int', 0, 'vararg')]
|
||||
function = Function('long', 0, name, args)
|
||||
|
||||
# Some syscalls have different names on different architectures,
|
||||
# or are superceded. We try to do the "best" thing at runtime.
|
||||
syscalls = fix_syscall_names(syscall)
|
||||
|
||||
# Set up the argument string for Mako
|
||||
argument_names = []
|
||||
argument_defaults = []
|
||||
|
||||
#
|
||||
|
||||
for arg in function.args:
|
||||
argname = fix_bad_arg_names(function, arg)
|
||||
default = get_arg_default(arg)
|
||||
|
||||
# Mako is unable to use *vararg and *kwarg, so we just stub in
|
||||
# a whole bunch of additional arguments.
|
||||
if argname == 'vararg':
|
||||
for j in range(5):
|
||||
argname = 'vararg_%i' % j
|
||||
argument_names.append(argname)
|
||||
argument_defaults.append('%s=%s' % (argname, None))
|
||||
break
|
||||
|
||||
argument_names.append(argname)
|
||||
argument_defaults.append('%s=%s' % (argname, default))
|
||||
|
||||
arguments_default_values = ', '.join(argument_defaults)
|
||||
arguments_comma_separated = ', '.join(argument_names)
|
||||
|
||||
string_arguments = []
|
||||
array_arguments = []
|
||||
arg_docs = []
|
||||
|
||||
for arg in function.args:
|
||||
|
||||
if can_be_array(arg):
|
||||
array_arguments.append(arg.name)
|
||||
|
||||
if can_be_string(arg):
|
||||
string_arguments.append(arg.name)
|
||||
|
||||
argname = arg.name
|
||||
argtype = str(arg.type) + ('*' * arg.derefcnt)
|
||||
arg_docs.append(
|
||||
' {argname}({argtype}): {argname}'.format(argname=argname,
|
||||
argtype=argtype))
|
||||
|
||||
return_type = str(function.type) + ('*' * function.derefcnt)
|
||||
arg_docs = '\n'.join(arg_docs)
|
||||
|
||||
template_variables = {
|
||||
'name': name,
|
||||
'arg_docs': arg_docs,
|
||||
'syscalls': syscalls,
|
||||
'arguments_default_values': arguments_default_values,
|
||||
'arguments_comma_separated': arguments_comma_separated,
|
||||
'return_type': return_type,
|
||||
'string_arguments': string_arguments,
|
||||
'array_arguments': array_arguments,
|
||||
'argument_names': argument_names,
|
||||
}
|
||||
|
||||
lines = [
|
||||
HEADER,
|
||||
DOCSTRING.format(**template_variables),
|
||||
ARGUMENTS.format(**template_variables),
|
||||
CALL.format(**template_variables)
|
||||
]
|
||||
|
||||
with open(os.path.join(target, name + '.asm'), 'wt+') as f:
|
||||
f.write('\n'.join(map(str.strip, lines)))
|
||||
|
||||
if __name__ == '__main__':
|
||||
p = argparse.ArgumentParser()
|
||||
p.add_argument('target_directory')
|
||||
args = p.parse_args()
|
||||
main(args.target_directory)
|
||||
+2
-1
@@ -4,12 +4,13 @@ class Device(object):
|
||||
bits = None
|
||||
endian = None
|
||||
serial = None
|
||||
os = None
|
||||
|
||||
def __init__(self, serial=None):
|
||||
self.serial = serial
|
||||
|
||||
def __str__(self):
|
||||
return self.serial
|
||||
|
||||
|
||||
def __eq__(self, other):
|
||||
return self.serial == other or self.serial == str(other)
|
||||
+24
-11
@@ -47,20 +47,22 @@ Example
|
||||
|
||||
DynELF
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
import ctypes
|
||||
|
||||
from elftools.elf.enums import ENUM_D_TAG
|
||||
|
||||
from . import elf
|
||||
from . import libcdb
|
||||
from .context import context
|
||||
from .elf import ELF
|
||||
from .elf import constants
|
||||
from .log import getLogger
|
||||
from .memleak import MemLeak
|
||||
from .util.fiddling import enhex
|
||||
from .util.packing import unpack
|
||||
from .util.web import wget
|
||||
from pwnlib import elf
|
||||
from pwnlib import libcdb
|
||||
from pwnlib.context import context
|
||||
from pwnlib.elf import ELF
|
||||
from pwnlib.elf import constants
|
||||
from pwnlib.log import getLogger
|
||||
from pwnlib.memleak import MemLeak
|
||||
from pwnlib.util.fiddling import enhex
|
||||
from pwnlib.util.packing import unpack
|
||||
from pwnlib.util.web import wget
|
||||
|
||||
log = getLogger(__name__)
|
||||
sizeof = ctypes.sizeof
|
||||
@@ -512,7 +514,7 @@ class DynELF(object):
|
||||
If set to ``'libc'``, ``'libc.so'`` is assumed.
|
||||
|
||||
Returns:
|
||||
Address of the named symbol, or ``None``.
|
||||
Address of the named symbol, or :const:`None`.
|
||||
"""
|
||||
result = None
|
||||
|
||||
@@ -860,3 +862,14 @@ class DynELF(object):
|
||||
self.success('*environ: %#x' % stack)
|
||||
|
||||
return stack
|
||||
|
||||
def heap(self):
|
||||
"""Finds the beginning of the heap via __curbrk, which is an exported
|
||||
symbol in the linker, which points to the current brk.
|
||||
"""
|
||||
curbrk = self.lookup('__curbrk', 'libc')
|
||||
brk = self.leak.p(curbrk)
|
||||
|
||||
self.success('*curbrk: %#x' % brk)
|
||||
|
||||
return brk
|
||||
+12
-4
@@ -1,6 +1,14 @@
|
||||
from .corefile import Core
|
||||
from .datatypes import *
|
||||
from .elf import ELF
|
||||
from .elf import load
|
||||
"""
|
||||
Most exploitable CTF challenges are provided in the Executable and Linkable
|
||||
Format (``ELF``). Generally, it is very useful to be able to interact with
|
||||
these files to extract data such as function addresses, ROP gadgets, and
|
||||
writable page addresses.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
|
||||
from pwnlib.elf.corefile import Core
|
||||
from pwnlib.elf.datatypes import *
|
||||
from pwnlib.elf.elf import ELF
|
||||
from pwnlib.elf.elf import load
|
||||
|
||||
__all__ = ['load', 'ELF', 'Core'] + sorted(filter(lambda x: not x.startswith('_'), datatypes.__dict__.keys()))
|
||||
@@ -0,0 +1,258 @@
|
||||
"""
|
||||
Kernel-specific ELF functionality
|
||||
"""
|
||||
|
||||
|
||||
class KernelConfig(object):
|
||||
def __init__(self, name, title, requires=[], excludes=[], minver=0, maxver=99):
|
||||
|
||||
#: Name of the configuration option
|
||||
self.name = name
|
||||
|
||||
#: Section to which the configuration point belongs
|
||||
self.title = title
|
||||
|
||||
#: List of configuration items, one of which must be present,
|
||||
#: for this checker to be used.
|
||||
self.requires = set(requires)
|
||||
|
||||
#: List of configuration items, NONE of which must be present,
|
||||
#: for this checker to be used.
|
||||
self.excludes = set(excludes)
|
||||
|
||||
#: Kernel version that this check should be enforced on
|
||||
self.minver = map(int, str(minver).split('.'))
|
||||
self.maxver = map(int, str(maxver).split('.'))
|
||||
|
||||
def relevant(self, config):
|
||||
|
||||
# If any of the excluded options are ENABLED,
|
||||
# this config is not relevant.
|
||||
if self.excludes:
|
||||
for value in self.excludes & set(config):
|
||||
if config.get(value, False):
|
||||
return False
|
||||
|
||||
# If any of the required options are PRESENT but DISABLED,
|
||||
# this config is not relevant.
|
||||
if self.requires:
|
||||
for value in self.requires & set(config):
|
||||
if config.get(value, False):
|
||||
return True
|
||||
|
||||
# We did not find a required value
|
||||
return False
|
||||
|
||||
# If we are not in the correct version range, bail
|
||||
if 'version' in config:
|
||||
version = config['version']
|
||||
|
||||
if not (self.minver <= version < self.maxver):
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
def check(self, value):
|
||||
raise NotImplementedError()
|
||||
|
||||
def __call__(self, config):
|
||||
"""__call__(config) -> str
|
||||
|
||||
Check whether the configuration point is set correctly.
|
||||
|
||||
Arguments:
|
||||
config(dict): Dictionary of all configuration points
|
||||
|
||||
Returns:
|
||||
A tuple (result, message) where result is whether the
|
||||
option is correctly configured, and message is an optional
|
||||
message describing the error.
|
||||
"""
|
||||
if not self.relevant(config):
|
||||
return (True, '')
|
||||
return self.check(config.get(self.name, None))
|
||||
|
||||
class Enabled(KernelConfig):
|
||||
def __init__(self, name, **kw):
|
||||
super(Enabled, self).__init__(name, 'Not Enabled', **kw)
|
||||
def check(self, config):
|
||||
return (bool(config), '')
|
||||
|
||||
class EnabledIfPresent(Enabled):
|
||||
def check(self, config):
|
||||
if config is None:
|
||||
return (True, '')
|
||||
return super(EnabledIfPresent, self).check(config)
|
||||
|
||||
class Disabled(KernelConfig):
|
||||
def __init__(self, name, **kw):
|
||||
super(Disabled, self).__init__(name, 'Not Disabled', **kw)
|
||||
def check(self, config):
|
||||
return (not bool(config), '')
|
||||
|
||||
class Minimum(KernelConfig):
|
||||
def __init__(self, name, minimum, **kw):
|
||||
super(Minimum, self).__init__(name, 'Misconfigured', **kw)
|
||||
self.minimum = minimum
|
||||
def check(self, value):
|
||||
if value is None or value < self.minimum:
|
||||
return (False, "Should be at least {}".format(self.minimum))
|
||||
return (True, '')
|
||||
|
||||
kernel_configuration = [
|
||||
# Enabled
|
||||
Enabled('STRICT_DEVMEM', requires=['DEVMEM']),
|
||||
Enabled('IO_STRICT_DEVMEM', requires=['DEVMEM']),
|
||||
Enabled('SYN_COOKIES'),
|
||||
Enabled('DEBUG_CREDENTIALS'),
|
||||
Enabled('DEBUG_NOTIFIERS'),
|
||||
Enabled('DEBUG_LIST'),
|
||||
Enabled('SECCOMP'),
|
||||
Enabled('SECCOMP_FILTER', minver=3.5, requires=['HAVE_ARCH_SECCOMP_FILTER']),
|
||||
Enabled('SECURITY'),
|
||||
# Enabled('SECURITY_YAMA'),
|
||||
Enabled('HARDENED_USERCOPY', minver=4.8),
|
||||
Enabled('SLAB_FREELIST_RANDOM', minver=4.7),
|
||||
# Enabled('SLUB_DEBUG'),
|
||||
# Enabled('PAGE_POISONING'),
|
||||
# Enabled('PAGE_POISONING_NO_SANITY'),
|
||||
# Enabled('PAGE_POISONING_ZERO'),
|
||||
Enabled('CC_STACKPROTECTOR', excludes=['CC_STACKPROTECTOR_STRONG']),
|
||||
Enabled('CC_STACKPROTECTOR_STRONG', minver=3.14),
|
||||
Enabled('PANIC_ON_OOPS', minver=3.5),
|
||||
Enabled('DEBUG_SET_MODULE_RONX', requires=['MODULES']),
|
||||
Enabled('DEBUG_RODATA'),
|
||||
Enabled('SECURITY_KPTR_RESTRICT'),
|
||||
Enabled('SECURITY_PERF_EVENTS_RESTRICT'),
|
||||
Enabled('SECURITY_DMESG_RESTRICT'),
|
||||
Enabled('SECURITY_NETWORK'),
|
||||
Enabled('SECURITY_SELINUX'),
|
||||
EnabledIfPresent('MSM_KERNEL_PROTECT'),
|
||||
|
||||
# Not really security relevant, but come on guys
|
||||
Enabled('COREDUMP'),
|
||||
|
||||
# Disabled
|
||||
Disabled('ACPI_CUSTOM_METHOD'),
|
||||
Disabled('COMPAT_BRK'),
|
||||
Disabled('DEVKMEM'),
|
||||
Disabled('DEVMEM'),
|
||||
Disabled('COMPAT_VDSO'),
|
||||
Disabled('KEXEC'),
|
||||
Disabled('BINFMT_MISC'),
|
||||
Disabled('LEGACY_PTYS'),
|
||||
Disabled('MODULES'),
|
||||
Disabled('KEXEC'),
|
||||
Disabled('SECURITY_SELINUX_DISABLE'),
|
||||
Disabled('MISC_FILESYSTEMS'),
|
||||
Disabled('SCSI_TGT'),
|
||||
Disabled('SCSI_CONSTANTS'),
|
||||
Disabled('SCSI_LOGGING'),
|
||||
Disabled('SCSI_SCAN_ASYNC'),
|
||||
Disabled('CONFIG_MEDIA_RADIO_SUPPORT'),
|
||||
Disabled('CONFIG_PFT'),
|
||||
Disabled('CONFIG_SYSVIPC'),
|
||||
|
||||
|
||||
# Permits reloading the kernel from disk
|
||||
Disabled('HIBERNATION'),
|
||||
|
||||
# Prior to v4.1, assists heap memory attacks; best to keep interface disabled
|
||||
Disabled('INET_DIAG', maxver=4.1),
|
||||
|
||||
|
||||
# x86-specific
|
||||
Enabled('HIGHMEM64G', requires=['X86_32']),
|
||||
Enabled('X86_PAE', requires=['X86_32']),
|
||||
Disabled('LEGACY_VSYSCALL_NONE', requires=['X86_32', 'X86_64'], minver=4.4),
|
||||
Disabled('CONFIG_IA32_EMULATION'),
|
||||
Disabled('X86_X32'),
|
||||
Disabled('MODIFY_LDT_SYSCALL'),
|
||||
Minimum('DEFAULT_MMAP_MIN_ADDR', 65536, requires=['X86_32', 'X86_64']),
|
||||
Enabled('RANDOMIZE_BASE', excludes=['ARM']),
|
||||
Enabled('RANDOMIZE_MEMORY', requires=['X86_64']),
|
||||
|
||||
# ARM specific
|
||||
Enabled('VMSPLIT_3G', requires=['ARM']),
|
||||
Disabled('STRICT_MEMORY_RWX', requires=['ARM', 'ARM64']),
|
||||
Minimum('DEFAULT_MMAP_MIN_ADDR', 32768, requires=['ARM', 'ARM64']),
|
||||
Minimum('ARCH_MMAP_RND_BITS', 16, requires=['ARM']),
|
||||
Minimum('ARCH_MMAP_RND_BITS', 24, requires=['ARM64']),
|
||||
Minimum('ARCH_MMAP_RND_COMPAT_BITS', 16, requires=['ARM64']),
|
||||
Enabled('CPU_SW_DOMAIN_PAN', requires=['ARM'], minver=4.3),
|
||||
Enabled('CONFIG_ARM64_PAN', requires=['ARM64'], minver=4.3),
|
||||
Disabled('OABI_COMPAT'),
|
||||
|
||||
# Only relevant of MODULES are enabled
|
||||
Enabled('MODULE_SIG', requires=['MODULES']),
|
||||
Enabled('MODULE_SIG_FORCE', requires=['MODULES']),
|
||||
Enabled('MODULE_SIG_ALL', requires=['MODULES']),
|
||||
Enabled('MODULE_SIG_SHA512', requires=['MODULES']),
|
||||
Enabled('MODULE_SIG_KEY', requires=['MODULES']),
|
||||
|
||||
]
|
||||
|
||||
def parse_kconfig(data):
|
||||
"""Parses configuration data from a kernel .config.
|
||||
|
||||
Arguments:
|
||||
data(str): Configuration contents.
|
||||
|
||||
Returns:
|
||||
A :class:`dict` mapping configuration options.
|
||||
"Not set" is converted into ``None``, ``y`` and ``n`` are converted
|
||||
into :class:`bool`. Numbers are converted into :class:`int`.
|
||||
All other values are as-is.
|
||||
Each key has ``CONFIG_`` stripped from the beginning.
|
||||
|
||||
Examples:
|
||||
|
||||
>>> parse_kconfig('FOO=3')
|
||||
{'FOO': 3}
|
||||
>>> parse_kconfig('FOO=y')
|
||||
{'FOO': True}
|
||||
>>> parse_kconfig('FOO=n')
|
||||
{'FOO': False}
|
||||
>>> parse_kconfig('FOO=bar')
|
||||
{'FOO': 'bar'}
|
||||
>>> parse_kconfig('# FOO is not set')
|
||||
{'FOO': None}
|
||||
"""
|
||||
config = {}
|
||||
|
||||
NOT_SET=' is not set'
|
||||
|
||||
if not data:
|
||||
return
|
||||
|
||||
for line in data.splitlines():
|
||||
|
||||
# Not set? Then set to None.
|
||||
if NOT_SET in line:
|
||||
line = line.split(NOT_SET, 1)[0]
|
||||
name = line.strip('# ')
|
||||
config[name] = None
|
||||
|
||||
# Set to a value? Extract it
|
||||
if '=' in line:
|
||||
k, v = line.split('=', 1)
|
||||
|
||||
# Boolean conversions
|
||||
if v == 'y':
|
||||
v = True
|
||||
elif v == 'n':
|
||||
v = False
|
||||
else:
|
||||
|
||||
# Integer conversions
|
||||
try:
|
||||
v = int(v, 0)
|
||||
except ValueError:
|
||||
pass
|
||||
|
||||
config[k] = v
|
||||
|
||||
|
||||
# Strip off all of the CONFIG_ prefixes
|
||||
config = ({k.replace('CONFIG_', ''): v for k,v in config.items()})
|
||||
return config
|
||||
+992
-64
File diff suppressed because it is too large.
Load diff
+84
-1
@@ -533,19 +533,102 @@ class user_regs_struct_amd64(ctypes.Structure):
|
||||
|
||||
assert ctypes.sizeof(user_regs_struct_amd64) == 0xd8
|
||||
|
||||
class user_regs_struct_arm(ctypes.Structure):
|
||||
_fields_ = [('r%i' % i, ctypes.c_uint32) for i in range(18)]
|
||||
|
||||
@property
|
||||
def cpsr(self):
|
||||
return self.r16
|
||||
@property
|
||||
def pc(self):
|
||||
return self.r15
|
||||
@property
|
||||
def lr(self):
|
||||
return self.r14
|
||||
@property
|
||||
def sp(self):
|
||||
return self.r13
|
||||
@property
|
||||
def ip(self):
|
||||
return self.r12
|
||||
@property
|
||||
def fp(self):
|
||||
return self.r11
|
||||
|
||||
|
||||
class user_regs_struct_aarch64(ctypes.Structure):
|
||||
_fields_ = [('x%i' % i, ctypes.c_uint64) for i in range(31)] \
|
||||
+ [('sp', ctypes.c_uint64),
|
||||
('pc', ctypes.c_uint64),
|
||||
('pstate', ctypes.c_uint64)]
|
||||
|
||||
@property
|
||||
def lr(self):
|
||||
return self.x30
|
||||
|
||||
def __getattr__(self, name):
|
||||
if name.startswith('r'):
|
||||
name = 'x' + name[1:]
|
||||
return getattr(name) & 0xffffffff
|
||||
|
||||
class elf_prstatus_i386(ctypes.Structure):
|
||||
_fields_ = generate_prstatus_common(32, user_regs_struct_i386)
|
||||
|
||||
assert ctypes.sizeof(elf_prstatus_i386) == 0x90
|
||||
|
||||
class elf_prstatus_amd64(ctypes.Structure):
|
||||
_fields_ = generate_prstatus_common(64, user_regs_struct_amd64)
|
||||
_fields_ = generate_prstatus_common(64, user_regs_struct_amd64) \
|
||||
+ [('padding', ctypes.c_uint32)]
|
||||
|
||||
assert ctypes.sizeof(elf_prstatus_amd64) == 0x150
|
||||
|
||||
class elf_prstatus_arm(ctypes.Structure):
|
||||
_fields_ = generate_prstatus_common(32, user_regs_struct_arm)
|
||||
|
||||
class elf_prstatus_aarch64(ctypes.Structure):
|
||||
_fields_ = generate_prstatus_common(64, user_regs_struct_aarch64)
|
||||
|
||||
class Elf32_auxv_t(ctypes.Structure):
|
||||
_fields_ = [('a_type', ctypes.c_uint32),
|
||||
('a_val', ctypes.c_uint32),]
|
||||
class Elf64_auxv_t(ctypes.Structure):
|
||||
_fields_ = [('a_type', ctypes.c_uint64),
|
||||
('a_val', ctypes.c_uint64),]
|
||||
|
||||
def generate_prspinfo(long):
|
||||
return [
|
||||
('pr_state', byte),
|
||||
('pr_sname', char),
|
||||
('pr_zomb', byte),
|
||||
('pr_nice', byte),
|
||||
('pr_flag', long),
|
||||
('pr_uid', ctypes.c_ushort),
|
||||
('pr_gid', ctypes.c_ushort),
|
||||
('pr_pid', ctypes.c_int),
|
||||
('pr_ppid', ctypes.c_int),
|
||||
('pr_pgrp', ctypes.c_int),
|
||||
('pr_sid', ctypes.c_int),
|
||||
('pr_fname', char * 16),
|
||||
('pr_psargs', char * 80)
|
||||
]
|
||||
|
||||
class elf_prspinfo_32(ctypes.Structure):
|
||||
_fields_ = generate_prspinfo(Elf32_Addr)
|
||||
|
||||
class elf_prspinfo_64(ctypes.Structure):
|
||||
_fields_ = generate_prspinfo(Elf64_Addr)
|
||||
|
||||
def generate_siginfo(int_t, long_t):
|
||||
class siginfo_t(ctypes.Structure):
|
||||
_fields_ = [('si_signo', int_t),
|
||||
('si_errno', int_t),
|
||||
('si_code', int_t),
|
||||
('sigfault_addr', long_t),
|
||||
('sigfault_trapno', int_t)]
|
||||
return siginfo_t
|
||||
|
||||
class elf_siginfo_32(generate_siginfo(ctypes.c_uint32, ctypes.c_uint32)):
|
||||
pass
|
||||
|
||||
class elf_siginfo_64(generate_siginfo(ctypes.c_uint32, ctypes.c_uint64)):
|
||||
pass
|
||||
+698
-177
File diff suppressed because it is too large.
Load diff
+13
-11
@@ -2,14 +2,16 @@
|
||||
"""
|
||||
Encode shellcode to avoid input filtering and impress your friends!
|
||||
"""
|
||||
from . import amd64
|
||||
from . import arm
|
||||
from . import i386
|
||||
from . import mips
|
||||
from .encoder import Encoder
|
||||
from .encoder import alphanumeric
|
||||
from .encoder import encode
|
||||
from .encoder import line
|
||||
from .encoder import null
|
||||
from .encoder import printable
|
||||
from .encoder import scramble
|
||||
from __future__ import absolute_import
|
||||
|
||||
from pwnlib.encoders import amd64
|
||||
from pwnlib.encoders import arm
|
||||
from pwnlib.encoders import i386
|
||||
from pwnlib.encoders import mips
|
||||
from pwnlib.encoders.encoder import Encoder
|
||||
from pwnlib.encoders.encoder import alphanumeric
|
||||
from pwnlib.encoders.encoder import encode
|
||||
from pwnlib.encoders.encoder import line
|
||||
from pwnlib.encoders.encoder import null
|
||||
from pwnlib.encoders.encoder import printable
|
||||
from pwnlib.encoders.encoder import scramble
|
||||
@@ -1 +1,3 @@
|
||||
from . import delta
|
||||
from __future__ import absolute_import
|
||||
|
||||
from pwnlib.encoders.amd64 import delta
|
||||
@@ -1,4 +1,6 @@
|
||||
from ..i386.delta import i386DeltaEncoder
|
||||
from __future__ import absolute_import
|
||||
|
||||
from pwnlib.encoders.i386.delta import i386DeltaEncoder
|
||||
|
||||
|
||||
class amd64DeltaEncoder(i386DeltaEncoder):
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
from . import alphanumeric
|
||||
from . import xor
|
||||
from __future__ import absolute_import
|
||||
|
||||
from pwnlib.encoders.arm import alphanumeric
|
||||
from pwnlib.encoders.arm import xor
|
||||
@@ -1,12 +1,13 @@
|
||||
from __future__ import absolute_import
|
||||
|
||||
import binascii
|
||||
import random
|
||||
import string
|
||||
import sys
|
||||
|
||||
import builder
|
||||
|
||||
from ....context import context
|
||||
from ...encoder import Encoder
|
||||
from pwnlib.context import context
|
||||
from pwnlib.encoders.arm.alphanumeric import builder
|
||||
from pwnlib.encoders.encoder import Encoder
|
||||
|
||||
|
||||
class ArmEncoder(Encoder):
|
||||
|
||||
Loaded 100 of 3594 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user