Giter Club home page Giter Club logo

pwndocker's Introduction

Pwndocker

A docker environment for pwn in ctf based on phusion/baseimage:focal-1.2.0, which is a modified ubuntu 20.04 baseimage for docker

Usage

docker-compose up -d
docker exec -it pwn_test /bin/bash

included software

  • pwntools —— CTF framework and exploit development library
  • pwndbg —— a GDB plug-in that makes debugging with GDB suck less, with a focus on features needed by low-level software developers, hardware hackers, reverse-engineers and exploit developers
  • pwngdb —— gdb for pwn
  • ROPgadget —— facilitate ROP exploitation tool
  • roputils —— A Return-oriented Programming toolkit
  • one_gadget —— A searching one-gadget of execve('/bin/sh', NULL, NULL) tool for amd64 and i386
  • angr —— A platform-agnostic binary analysis framework
  • radare2 —— A rewrite from scratch of radare in order to provide a set of libraries and tools to work with binary files
  • seccomp-tools —— Provide powerful tools for seccomp analysis
  • linux_server[64] —— IDA 7.0 debug server for linux
  • tmux —— a terminal multiplexer
  • ltrace —— trace library function call
  • strace —— trace system call

included glibc

Default compiled glibc path is /glibc.

  • 2.19 —— ubuntu 12.04 default libc version
  • 2.23 —— ubuntu 16.04 default libc version
  • 2.24 —— introduce vtable check in file struct
  • 2.27 —— ubuntu 18.04 default glibc version
  • 2.31 —— ubuntu 20.04 default glibc version(built-in)
  • 2.282.30,2.332.36 —— latest libc versions

Q&A

How to run in custom libc version?

cp /glibc/2.27/64/lib/ld-2.27.so /tmp/ld-2.27.so
patchelf --set-interpreter /tmp/ld-2.27.so ./test
LD_PRELOAD=./libc.so.6 ./test

or

from pwn import *
p = process(["/path/to/ld.so", "./test"], env={"LD_PRELOAD":"/path/to/libc.so.6"})

How to run in custom libc version with other lib?

if you want to run binary with glibc version 2.28:

root@pwn:/ctf/work# ldd /bin/ls
linux-vdso.so.1 (0x00007ffe065d3000)
libselinux.so.1 => /lib/x86_64-linux-gnu/libselinux.so.1 (0x00007f004089e000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f00406ac000)
libpcre2-8.so.0 => /lib/x86_64-linux-gnu/libpcre2-8.so.0 (0x00007f004061c000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f0040616000)
/lib64/ld-linux-x86-64.so.2 (0x00007f00408f8000)

root@pwn:/ctf/work# /glibc/2.28/64/ld-2.28.so /bin/ls
/bin/ls: error while loading shared libraries: libselinux.so.1: cannot open shared object file: No such file or directory

You can copy /lib/x86_64-linux-gnu/libselinux.so.1 and /lib/x86_64-linux-gnu/libpcre2-8.so.0 to /glibc/2.28/64/lib/, and sometimes it fails because the built-in libselinux.so.1 requires higher version libc:

root@pwn:/ctf/work# /glibc/2.28/64/ld-2.28.so /bin/ls
/bin/ls: /glibc/2.28/64/lib/libc.so.6: version `GLIBC_2.30' not found (required by /glibc/2.28/64/lib/libselinux.so.1)

it can be solved by copying libselinux.so.1 from ubuntu 18.04 which glibc version is 2.27 to /glibc/2.28/64/lib:

docker run -itd --name u18 ubuntu:18.04 /bin/bash
docker cp -L u18:/lib/x86_64-linux-gnu/libselinux.so.1 .
docker cp -L u18:/lib/x86_64-linux-gnu/libpcre2-8.so.0 .
docker cp libselinux.so.1 pwn:/glibc/2.28/64/lib/
docker cp libpcre2-8.so.0 pwn:/glibc/2.28/64/lib/

And now it succeeds:

root@pwn:/ctf/work# /glibc/2.28/64/ld-2.28.so /bin/ls -l /

ChangeLog

2023-10-22

add zsh and ohmyzsh to docker image, update pwntools version to 4.11.0

2023-01-27

add glibc versions 2.33~2.36 to docker image, and update pwntools version to 4.9.0

2022-03-06

add pwntools_version docker build argument, 4.8.0b0 is set in repo docker build actions

2022-2-10

add docker-compose.yml

2021-10-25

add docker build action and update radare2 version to latest

2020-09-06

update base image to 20.04(glibc 2.31) and add glibc 2.27

2020-05-22

update radare2 to version 4.4.0 and add r2pipe python binding

2020-04-11

add libc 2.30 and 2.31

2020-02-19

python packages switched to python3 version, remove roputils.py

pwndocker's People

Contributors

skysider avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pwndocker's Issues

gdb attach won't work

When I tring to use gdb.attach(io) in py script using pwntools.
An Error occurred said :
Waiting for debugger: debugger exited! (maybe check /proc/sys/kernel/yama/ptrace_scope)
image

Here is my exp code:

from pwn import *
context.log_level = "debug"
context.terminal = ["tmux","splitw","-h"]
io = process("./login") 
io.recvuntil("Input the username:")
io.sendline("a"*0x7a)
gdb.attach(io)
io.recvuntil("Input the password:")
io.sendline("b"*0x10)
io.interactive()

I have searched for this problem and tried method listed as below,All of them didn't work:

  1. add --privilidged option to the docker start file:
     docker run -d \
        --rm \
        -h $1 \
        --name $1 \
        -v $(pwd)/$1:/ctf/work \
        -p 23946:23946 \
        --privileged \
        --cap-add=SYS_PTRACE \
        skysider/pwndocker
    
     docker exec -it $1 /bin/bash
  2. add --security-opt seccomp=unconfined option to the docker start file:
      docker run -d \
        --rm \
        -h $1 \
        --name $1 \
        -v $(pwd)/$1:/ctf/work \
        -p 23946:23946 \
        --privileged \
        --cap-add=SYS_PTRACE \
        --security-opt seccomp=unconfined \
        skysider/pwndocker
    
       docker exec -it $1 /bin/bash
  3. add --security-opt apparmor=unconfined option to the docker start file:
      docker run -d \
        --rm \
        -h $1 \
        --name $1 \
        -v $(pwd)/$1:/ctf/work \
        -p 23946:23946 \
        --privileged \
        --cap-add=SYS_PTRACE \
        --security-opt apparmor=unconfined \
        --security-opt seccomp=unconfined \
        skysider/pwndocker
    
       docker exec -it $1 /bin/bash
  4. run echo 0 > /proc/sys/kernel/yama/ptrace_scope

Basic System Information:
Machine that running docker: Ubuntu 20.04 running on Virtual Box

pwn version is not for tmux

git clone --depth 1 https://github.com.cnpmjs.org/Gallopsled/pwntools.git
pip install --upgrade --editable ./pwntools

there's not roputils but it is included in README.md

Notice that roputils is included in README, but actually I can't import it in neither python2 nor python3. I have checked Dockerfile and find it seems that nothing about roputils exists, which makes me confused.
Thank you so much.

Error: Authentication required to pull the image

Hi,

first of all, thanks for this image, it has been of great help when pwning!
I think there is an issue with the Dockerfile, as pulling the image from scratch yields to an error:

> docker pull skysider/pwndocker:latest
latest: Pulling from skysider/pwndocker
345e3491a907: Pull complete 
57671312ef6f: Pull complete 
5e9250ddb7d0: Pull complete 
469c73a16ba5: Pull complete 
6d234dc15284: Pull complete 
42cbb779a68f: Pull complete 
726d55798abf: Downloading [=========================>                         ]  156.5MB/306MB
511af35a6a8b: Download complete 
18c5e01ba678: Download complete 
5f90fb92201d: Download complete 
e376bbea8312: Download complete 
14641206fa09: Download complete 
1ea7e5742d7c: Download complete 
a2aa00890aee: Download complete 
d726458fad58: Downloading [=====>                                             ]  33.76MB/294.8MB
8f7ea1bd4f01: Download complete 
0e3bb34b7406: Download complete 
6ef28762945f: Downloading 
bf5fd95ca7c6: Waiting 
dfc489ce0e2d: Waiting 
0bf33740dafa: Waiting 
b98b027f6ebd: Waiting 
8acef8e579a8: Waiting 
2ee39d26bcf6: Waiting 
12441af2add7: Waiting 
c70656af2b50: Waiting 
2d0d71ee97a3: Waiting 
50ea63e52fc0: Waiting 
e9a6fb786549: Waiting 
3a54190c7994: Waiting 
d96ea314b9a1: Waiting 
docker: unauthorized: authentication required.   <------------ Error here!

It looks like it happens when docker tries to download the image with (partial?) hash 6ef28762945f.

How to reproduce

Steps:

  1. Remove the image locally
  2. Pull the image again

Feature request: include glibc 2.34~2.36 in the docker image

This repo is really useful! Thanks for sharing.

The glibc included in the docker image are kind of outdated. Ubuntu 22.04 now uses glibc 2.35 but the image only support glibc 2.31. Can we add the latest libc (2.34~2.36) to the docker image?

I can't change the interpreter

I run

patchelf --set-interpreter /glibc/2.23/64/lib/ld-2.23.so ./binary

and I run ldd on the binary
/glibc/2.23/64/lib/ld-2.23.so => /usr/lib64/ld-linux-x86-64.so.2 (0x00007f0118a0a000)

It stills points to the default libc. If I try to set LD_PRELOAD to the 2.23 libc, it crashes.

gdb can't disable ASLR inside the container

While trying to open up a binary with gdb inside the container, it reports:

warning: Error disabling address space randomization: Operation not permitted

A Stack Overflow answer suggested adding a --security-opt seccomp=unconfined option on the command line. The docker-compose version of this would be:

security_opt:
    - seccomp:unconfined

Adding this option to the docker-compose.yml makes gdb work properly. I would just open up a PR but I'm not sure if this is the right approach. The issue is there, modifying the docker-compose.yml file is just a suggestion.

When I tring to use gdb.attach(io) in py script using pwntools. An Error occurred said

when running exploit script and attaching dynamically or not even interracting with binary and after process started if I attach i get this Traceback (most recent call last):
File "hack20.py", line 9, in
gdb.attach(p)
File "/usr/local/lib/python3.8/dist-packages/pwnlib/context/init.py", line 1543, in setter
return function(a, **kw)
File "/usr/local/lib/python3.8/dist-packages/pwnlib/gdb.py", line 1051, in attach
gdb_pid = misc.run_in_new_terminal(cmd, preexec_fn = preexec_fn)
File "/usr/local/lib/python3.8/dist-packages/pwnlib/util/misc.py", line 297, in run_in_new_terminal
pid = int(out)
ValueError: invalid literal for int() with base 10: b''
[
] Stopped process './sint' (pid 20)

there is no angr but it is included in readme.md

Notice that angr is included in README, but actually I can't import it in neither python2 nor python3. I have checked Dockerfile and find it seems that nothing about angr exists, which makes me confused.
Thank you so much.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.