-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsolve-part4.rb
executable file
·59 lines (48 loc) · 1.21 KB
/
solve-part4.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env ruby
require 'open-uri'
HEADER_FILES = Dir["/usr/include/*/asm/unistd_64.h"] +
Dir["/usr/src/linux*/arch/x86/include/asm/unistd_64.h"]
HEADER_URL = "http://lxr.linux.no/linux+v2.6.37/+save=arch/x86/include/asm/unistd_64.h"
if ARGV.size != 1 then
$stderr.puts "usage: solve-part4.rb input ( - for stdin)"
exit(1)
end
data = nil
input = ARGV.first
if input == "-" then
data = $stdin.read
else
data = File.read(input)
end
$stderr.puts "[*] solving part 4"
syscalls = nil
data.each_line do |line|
if line =~ /sys_socketpair/ then
syscalls = line.chomp.split(':', 2).last.split(/\s+/)
break
end
end
headers_data = nil
HEADER_FILES.each do |path|
if File.exist? path then
$stderr.puts "[+] found syscall definitions at #{path}"
headers_data = File.read(path)
break
end
end
unless headers_data
$stderr.puts "[+] downloading syscall definitions from #{HEADER_URL}"
headers_data = open(HEADER_URL).read
end
b = {}
headers_data.each_line do |line|
if line =~ /define __NR_([^\s]+)\s+(\d+)/ then
b["sys_#{$1}"] = $2.to_i
b["stub_#{$1}"] = $2.to_i
end
end
a = syscalls.map {|x| b[x]}
raise if a.include? nil
email = a.pack('C*')
$stderr.puts "[!] email: #{email}"
puts email