@@ -14,8 +14,25 @@ def initialize
14
14
'Name' => 'UPnP AddPortMapping' ,
15
15
'Description' => 'UPnP AddPortMapping SOAP request' ,
16
16
'Author' => 'St0rn <[email protected] >' ,
17
- 'License' => MSF_LICENSE
17
+ 'License' => MSF_LICENSE ,
18
+ 'Actions' =>
19
+ [
20
+ [ 'ADD' ,
21
+ {
22
+ 'Description' => 'Use the AddPortMapping SOAP command to open and forward a port' ,
23
+ 'SOAP_ACTION' => 'AddPortMapping'
24
+ }
25
+ ] ,
26
+ [ 'DELETE' ,
27
+ {
28
+ 'Description' => 'Use the DeletePortMapping SOAP command to remove a port forwarding' ,
29
+ 'SOAP_ACTION' => 'DeletePortMapping'
30
+ }
31
+ ]
32
+ ] ,
33
+ 'DefaultAction' => 'ADD'
18
34
)
35
+
19
36
register_options (
20
37
[
21
38
OptString . new ( 'TARGETURI' , [ true , 'UPnP control URL' , '/' ] ) ,
@@ -54,20 +71,31 @@ def protocol
54
71
@protocol ||= datastore [ 'PROTOCOL' ]
55
72
end
56
73
74
+ def soap_action
75
+ @soap_action ||= action . opts [ 'SOAP_ACTION' ]
76
+ end
77
+
57
78
def run
58
79
content = "<?xml version=\" 1.0\" ?>"
59
80
content << "<SOAP-ENV:Envelope xmlns:SOAP-ENV=\" http://schemas.xmlsoap.org/soap/envelope\" SOAP-ENV:encodingStyle=\" http://schemas.xmlsoap.org/soap/encoding/\" >"
60
81
content << "<SOAP-ENV:Body>"
61
- content << "<m:AddPortMapping xmlns:m=\" urn:schemas-upnp-org:service:WANIPConnection:1\" >"
62
- content << "<NewPortMappingDescription>#{ Rex ::Text . rand_text_alpha ( 8 ) } </NewPortMappingDescription>"
63
- content << "<NewLeaseDuration>#{ lease_duration } </NewLeaseDuration>"
64
- content << "<NewInternalClient>#{ internal_client } </NewInternalClient>"
65
- content << "<NewEnabled>1</NewEnabled>"
66
- content << "<NewExternalPort>#{ external_port } </NewExternalPort>"
67
- content << "<NewRemoteHost>#{ external_client } </NewRemoteHost>"
68
- content << "<NewProtocol>#{ protocol } </NewProtocol>"
69
- content << "<NewInternalPort>#{ internal_port } </NewInternalPort>"
70
- content << "</m:AddPortMapping>"
82
+ content << "<m:#{ soap_action } xmlns:m=\" urn:schemas-upnp-org:service:WANIPConnection:1\" >"
83
+ case action . name
84
+ when 'ADD'
85
+ content << "<NewPortMappingDescription>#{ Rex ::Text . rand_text_alpha ( 8 ) } </NewPortMappingDescription>"
86
+ content << "<NewLeaseDuration>#{ lease_duration } </NewLeaseDuration>"
87
+ content << "<NewInternalClient>#{ internal_client } </NewInternalClient>"
88
+ content << "<NewEnabled>1</NewEnabled>"
89
+ content << "<NewExternalPort>#{ external_port } </NewExternalPort>"
90
+ content << "<NewRemoteHost>#{ external_client } </NewRemoteHost>"
91
+ content << "<NewProtocol>#{ protocol } </NewProtocol>"
92
+ content << "<NewInternalPort>#{ internal_port } </NewInternalPort>"
93
+ when 'DELETE'
94
+ content << "<NewExternalPort>#{ external_port } </NewExternalPort>"
95
+ content << "<NewRemoteHost>#{ external_client } </NewRemoteHost>"
96
+ content << "<NewProtocol>#{ protocol } </NewProtocol>"
97
+ end
98
+ content << "</m:#{ soap_action } >"
71
99
content << "</SOAP-ENV:Body>"
72
100
content << "</SOAP-ENV:Envelope>"
73
101
@@ -77,21 +105,22 @@ def run
77
105
'content-type' => 'text/xml;charset="utf-8"' ,
78
106
'data' => content ,
79
107
'headers' => {
80
- 'SoapAction' => ' urn:schemas-upnp-org:service:WANIPConnection:1#AddPortMapping'
108
+ 'SoapAction' => " urn:schemas-upnp-org:service:WANIPConnection:1##{ soap_action } "
81
109
}
82
110
)
83
111
112
+ external_map = "#{ external_client ? external_client : 'any' } :#{ external_port } /#{ protocol } "
113
+ internal_map = "#{ internal_client ? internal_client : 'any' } :#{ internal_port } /#{ protocol } "
114
+ map = "#{ external_map } -> #{ internal_map } "
115
+
84
116
if res
85
- external_map = "#{ external_client ? external_client : 'any' } :#{ external_port } /#{ protocol } "
86
- internal_map = "#{ internal_client ? internal_client : 'any' } :#{ internal_port } /#{ protocol } "
87
- map = "#{ external_map } -> #{ internal_map } "
88
117
if res . code == 200
89
- print_good ( "#{ peer } successfully mapped #{ map } " )
118
+ print_good ( "#{ peer } #{ map } #{ action . name } succeeded " )
90
119
else
91
- print_error ( "#{ peer } failed to map #{ map } : #{ res } " )
120
+ print_error ( "#{ peer } #{ map } #{ action . name } failed : #{ res } " )
92
121
end
93
122
else
94
- print_error ( "#{ peer } no response for mapping #{ map } " )
123
+ print_error ( "#{ peer } no response for #{ map } #{ action . name } " )
95
124
end
96
125
end
97
126
end
0 commit comments