-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathtest-client
executable file
·211 lines (179 loc) · 4.85 KB
/
test-client
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
#!/usr/bin/env python
from rdp2tcp import rdp2tcp, R2TException
from sys import exit
import time
import socket
import os
def tcp_sock(local_port):
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0)
s.connect(('127.0.0.1', local_port))
s.settimeout(30)
return s
def cmd(cmdline):
os.system('xterm -e %s &' % cmdline)
###############################################################
# send shit to controller -> expect connection closed
def test_controller_proto():
badmsgs = [ \
'\n', \
' l\n', \
't\n', 'r\n', 's\n', 'x\n', \
's a 0\n', \
's a -1\n', \
's a 65536\n', \
's a 65535A\n', \
'\x00\n' \
]
print 'controller protocol tests'
for msg in badmsgs:
s = tcp_sock(8477)
s.sendall(msg)
data = s.recv(256)
if data != '':
print 'error: server didnt closed connection'
print '>>> ', repr(msg)
print '<<< ', data
s.close()
###############################################################
# python API test
def setup_tunnels():
print 'tunnels setup'
try:
r2t = rdp2tcp('127.0.0.1', 8477)
except R2TException, e:
print e
exit(0)
try:
# forward
r2t.add_tunnel('t', ('127.0.0.1',4444),('127.0.0.1',4444))
# forward
r2t.add_tunnel('t', ('127.0.0.1',4445),('127.0.0.1',445))
# reverse
r2t.add_tunnel('r', ('127.0.0.1',22),('127.0.0.1',2222))
# forward
r2t.add_tunnel('t', ('127.0.0.1',2222),('127.0.0.1',2222))
# forward
r2t.add_tunnel('t', ('::1',2223),('127.0.0.1',2222))
# forward
r2t.add_tunnel('t', ('localhost',2224),('127.0.0.1',2222))
# process
r2t.add_tunnel('x', ('127.0.0.1',4446),('cmd.exe',0))
# socks5
r2t.add_tunnel('s', ('127.0.0.1',65480),('',0))
print r2t.info()
except R2TException, e:
print e
r2t.close()
###############################################################
# test behaviour of buggy tunnel clients
def test_connect_and_close():
targets = [ \
8477, \
4444, \
4445, \
2222, \
4446, \
65480 \
]
print 'connect() + close() tests'
for port in targets:
s = tcp_sock(port)
s.close()
for port in targets:
print 'connect(%i) + sleep(2) + close() tests' % port
s = tcp_sock(port)
time.sleep(2)
s.close()
print 'connect() + send(garbage) + close() tests'
garbage = ''.join(chr(i) for i in xrange(0x100))
for port in targets:
s = tcp_sock(port)
s.sendall(garbage)
s.close()
###############################################################
# test ssh tunnel by boucing on remote host
# use forward tunnel + reverse tunnel
# server talks first
def test_ssh():
print '1 SSH test'
cmd('ssh -p 2222 127.0.0.1 "ls /usr/lib | less"')
raw_input('Press Key when SSH is closed')
print '2 SSH test'
cmd('ssh -p 2222 127.0.0.1 "ls /usr/lib | less"')
cmd('ssh -p 2222 127.0.0.1 "ls /usr/lib | less"')
raw_input('Press Key when both SSH are closed')
###############################################################
# test forward tunnel using "dir c:\windows\system32"
# server talks first
def test_cmd():
print 'cmd.exe test'
cmd('telnet 127.0.0.1 4446')
raw_input('Press Key when cmd.exe is closed')
###############################################################
# test forward tunnel using smbclient
# client talks first
def test_smb():
print 'smbclient test'
cmd('smbclient -U Administrator -p 4445 //127.0.0.1/c$')
raw_input('Press Key when smbclient is closed')
###############################################################
# test socks5 protocol errors
def test_socks5():
# expect connection closed
badmsgs = [ '\x00', '\x04', '\x06', '\x05\x00' ]
print 'socks5 protocol tests 1'
for msg in badmsgs:
s = tcp_sock(65480)
s.sendall(msg)
try:
data = s.recv(256)
if data != '' and da:
print 'error: socket5 server didnt closed connection'
print '>>> ', repr(msg)
print '<<< ', repr(data)
except socket.error, e:
if e[0] != 104:
print 'error: %s' % str(e)
print '>>> ', repr(msg)
s.close()
# expect socks5 error
badmsgs = [ \
'\x05\x01\x00\x00', \
'\x05\x01\x00\x05\x00', \
'\x05\x01\x00\x05\x02', \
'\x05\x01\x00\x05\x03', \
'\x05\x01\x00\x05\x00', \
'\x05\x01\x00\x05\x01\x01', \
'\x05\x01\x00\x05\x01\x00\x00', \
'\x05\x01\x00\x05\x01\x00\x02', \
'\x05\x01\x00\x05\x01\x00\xff', \
'\x05\x01\x00\x05\x01\x00\x03\x00', \
'\x05\x01\x00\x05\x01\x00\x03\x00\x41', \
]
print 'socks5 protocol tests 2'
for msg in badmsgs:
s = tcp_sock(65480)
s.sendall(msg)
try:
data = s.recv(256)
if len(data) != 2 or data[0] != '\x05':
print 'error: socket5 server didnt closed connection'
print '>>> ', repr(msg)
print '<<< ', repr(data)
except socket.error, e:
if e[0] != 104:
print 'error: %s' % str(e)
print '>>> ', repr(msg)
s.close()
if __name__ == '__main__':
socket.setdefaulttimeout(5)
setup_tunnels()
if 1:
#test_controller_proto()
#test_controller_proto()
test_connect_and_close()
#test_socks5()
#test_ssh()
#test_cmd()
#test_smb()
pass