@@ -8,7 +8,7 @@ module SessionSetupAndx
8
8
#
9
9
# Sets up an SMB session in response to a SESSION_SETUP_ANDX request
10
10
#
11
- def smb_cmd_session_setup ( c , buff )
11
+ def smb_cmd_session_setup_andx ( c , buff )
12
12
tree_connect_response = CONST ::SMB_TREE_CONN_ANDX_RES_PKT . make_struct
13
13
tree_connect_response . v [ 'WordCount' ] = 7
14
14
tree_connect_response . v [ 'AndXCommand' ] = CONST ::SMB_COM_NO_ANDX_COMMAND
@@ -19,26 +19,49 @@ def smb_cmd_session_setup(c, buff)
19
19
tree_connect_response . v [ 'GuestAccessRights' ] = 0
20
20
tree_connect_response . v [ 'Payload' ] = "A:\x00 #{ Rex ::Text . to_unicode ( 'NTFS' ) } \x00 \x00 "
21
21
22
+ data = Rex ::Text . to_unicode ( 'Unix' , 'utf-16be' ) + "\x00 \x00 " + # Native OS # Samba signature
23
+ Rex ::Text . to_unicode ( 'Samba 3.4.7' , 'utf-16be' ) + "\x00 \x00 " + # Native LAN Manager # Samba signature
24
+ Rex ::Text . to_unicode ( 'WORKGROUP' , 'utf-16be' ) + "\x00 \x00 \x00 " # Primary DOMAIN # Samba signature
25
+
26
+ send_session_setup_andx_res ( c , {
27
+ action : CONST ::SMB_SETUP_GUEST ,
28
+ data : data ,
29
+ andx : CONST ::SMB_COM_TREE_CONNECT_ANDX ,
30
+ andx_offset : 96 ,
31
+ andx_command : tree_connect_response
32
+ } )
33
+ end
34
+
35
+ def send_session_setup_andx_res ( c , opts = { } )
36
+ action = opts [ :action ] || 0
37
+ andx_offset = opts [ :andx_offset ] || 0
38
+ reserved = opts [ :reserved ] || 0
39
+ andx = opts [ :andx ] || CONST ::SMB_COM_NO_ANDX_COMMAND
40
+ data = opts [ :data ] || ''
41
+ andx_command = opts [ :andx_command ] || nil
42
+
43
+
22
44
pkt = CONST ::SMB_SETUP_RES_PKT . make_struct
23
45
smb_set_defaults ( c , pkt )
24
46
25
47
pkt [ 'Payload' ] [ 'SMB' ] . v [ 'Command' ] = CONST ::SMB_COM_SESSION_SETUP_ANDX
26
48
pkt [ 'Payload' ] [ 'SMB' ] . v [ 'Flags1' ] = FLAGS
27
49
pkt [ 'Payload' ] [ 'SMB' ] . v [ 'Flags2' ] = FLAGS2
28
50
pkt [ 'Payload' ] [ 'SMB' ] . v [ 'WordCount' ] = 3
29
- pkt [ 'Payload' ] . v [ 'AndX' ] = CONST ::SMB_COM_TREE_CONNECT_ANDX
30
- pkt [ 'Payload' ] . v [ 'Reserved1' ] = 00
31
- pkt [ 'Payload' ] . v [ 'AndXOffset' ] = 96
32
- pkt [ 'Payload' ] . v [ 'Action' ] = CONST ::SMB_SETUP_GUEST
33
- pkt [ 'Payload' ] . v [ 'Payload' ] =
34
- Rex ::Text . to_unicode ( 'Unix' , 'utf-16be' ) + "\x00 \x00 " + # Native OS # Samba signature
35
- Rex ::Text . to_unicode ( 'Samba 3.4.7' , 'utf-16be' ) + "\x00 \x00 " + # Native LAN Manager # Samba signature
36
- Rex ::Text . to_unicode ( 'WORKGROUP' , 'utf-16be' ) + "\x00 \x00 \x00 " # Primary DOMAIN # Samba signature
51
+ pkt [ 'Payload' ] . v [ 'AndX' ] = andx
52
+ pkt [ 'Payload' ] . v [ 'Reserved1' ] = reserved
53
+ pkt [ 'Payload' ] . v [ 'AndXOffset' ] = andx_offset
54
+ pkt [ 'Payload' ] . v [ 'Action' ] = action
55
+ pkt [ 'Payload' ] . v [ 'Payload' ] = data
37
56
38
- full_pkt = pkt . to_s + tree_connect_response . to_s
39
- original_length = full_pkt [ 2 , 2 ] . unpack ( 'n' ) [ 0 ]
40
- original_length = original_length + tree_connect_response . to_s . length
41
- full_pkt [ 2 , 2 ] = [ original_length ] . pack ( 'n' )
57
+ if andx_command
58
+ full_pkt = pkt . to_s + andx_command . to_s
59
+ original_length = full_pkt [ 2 , 2 ] . unpack ( 'n' ) [ 0 ]
60
+ original_length = original_length + andx_command . to_s . length
61
+ full_pkt [ 2 , 2 ] = [ original_length ] . pack ( 'n' )
62
+ else
63
+ full_pkt = pkt . to_s
64
+ end
42
65
43
66
c . put ( full_pkt )
44
67
end
0 commit comments