rubypwn first commitgit st1git st1

This commit is contained in:
Hung-Chi Su 2015-08-26 22:23:57 +08:00
commit e2092945b3
9 changed files with 158 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
.DS_Store
Gemfile.lock

5
Gemfile Normal file
View File

@ -0,0 +1,5 @@
source 'https://rubygems.org'
gem 'rainbow'
gem 'thread'
gem 'rest-client'

0
README Normal file
View File

20
lib/asm.rb Normal file
View File

@ -0,0 +1,20 @@
require 'rest-client'
require 'json'
require 'base64'
class Asm
# Supported Format: hex, c, binary
def self.compile(code, arch="i386", format="hex")
r = RestClient.post 'http://atdog.tw/asm/compile', :code => code, :arch => arch, :format => format
r = JSON.parse r
if r['result'] == 1
if format == "binary"
return Base64.decode64(r['code'])
else
return r['code']
end
else
raise "asm compile error. [code]: #{code}"
end
end
end

38
lib/basic.rb Normal file
View File

@ -0,0 +1,38 @@
def i16(int)
[int].pack("S<")
end
def i32(int)
[int].pack("L<")
end
def i64(int)
[int].pack("Q<")
end
def s16(int)
str = str.ljust(2, "\x00")
str.unpack("S<")[0]
end
def s32(str)
str = str.ljust(4, "\x00")
str.unpack("L<")[0]
end
def s64(str)
str = str.ljust(8, "\x00")
str.unpack("Q<")[0]
end
def c(int)
[int].pack("C")
end
def hex(str)
str.unpack("H*")[0]
end
def nop()
"\x90"
end

70
lib/exec.rb Normal file
View File

@ -0,0 +1,70 @@
require 'open3'
class Exec
public
def initialize(cmd)
handle_exception
@@i, @@o, s = Open3.popen2(cmd)
end
def read(size)
data = @@o.read size
write_flush $stdout, data
data
end
def readpartial(size)
data = @@o.readpartial size
write_flush $stdout, data
data
end
def write(data)
write_flush $stdout, data
write_flush @@i, data
end
def puts(data)
write "#{data}\n"
end
def gets
read_until "\n"
end
def read_until(str)
result = ""
loop do
result << @@o.read(1)
if result.end_with? str
write_flush $stdout, result
return result
end
end
end
def interactive
loop do
r = IO.select [@@o, $stdin]
if r[0].include? @@o
read 1
elsif r[0].include? $stdin
@@i.write $stdin.read(1)
end
end
end
private
def write_flush(fd, data)
fd.write data
fd.flush
end
def handle_exception
trap "SIGINT" do
$stdout.puts
$stdout.puts "interrupted"
exit -1
end
end
end

7
lib/netcat.rb Normal file
View File

@ -0,0 +1,7 @@
require_relative 'exec'
class Netcat < Exec
def initialize(ip, port)
super("nc #{ip} #{port}")
end
end

4
lib/rubypwn.rb Normal file
View File

@ -0,0 +1,4 @@
require_relative 'basic'
require_relative 'asm'
require_relative 'netcat'

12
rubypwn.gemspec Normal file
View File

@ -0,0 +1,12 @@
Gem::Specification.new do |s|
s.name = 'rubypwn'
s.version = '0.0.4'
s.date = '2015-08-26'
s.summary = "pwn tools - ruby version"
s.description = "pwn tools"
s.authors = ["atdog"]
s.email = 'atdog.tw@gmail.com'
s.files = ["lib/rubypwn.rb", "lib/basic.rb", "lib/netcat.rb", "lib/exec.rb", "lib/asm.rb"]
s.homepage = 'http://rubygems.org/gems/rubypwn'
s.license = 'MIT'
end