25
25
26
26
from w3af .core .controllers .plugins .audit_plugin import AuditPlugin
27
27
from w3af .core .controllers .misc .fuzzy_string_cmp import fuzzy_equal
28
- from w3af .core .controllers .misc .fuzzy_string_cmp import fuzzy_not_equal
29
28
from w3af .core .controllers .exceptions import HTTPRequestException
30
29
from w3af .core .data .fuzzer .fuzzer import create_mutants
31
30
from w3af .core .data .kb .vuln import Vuln
32
31
33
32
34
- MemcacheInjection = namedtuple ('MemcacheInjection' , ['ok' , 'error_1' , 'error_2' ])
33
+ MemcacheInjection = namedtuple ('MemcacheInjection' ,
34
+ ['ok' , 'error_1' , 'error_2' ])
35
35
36
36
37
37
class memcachei (AuditPlugin ):
38
38
39
+ OK = u'key1 0 30 1\r \n 1\r \n set injected 0 10 10\r \n 1234567890\r \n '
40
+ ERROR_1 = u'key1 0 f 1\r \n 1\r \n '
41
+ ERROR_2 = u'key1 0 30 0\r \n 1\r \n '
42
+
39
43
def __init__ (self ):
40
44
AuditPlugin .__init__ (self )
41
- self .mci = MemcacheInjection (u'key1 0 30 1\r \n 1\r \n '
42
- u'set injected 0 10 10\r \n 1234567890\r \n ' ,
43
- u'key1 0 f 1\r \n 1\r \n ' ,
44
- u'key1 0 30 0\r \n 1\r \n ' )
45
45
self ._eq_limit = 0.97
46
46
47
47
def audit (self , freq , orig_response ):
@@ -58,18 +58,14 @@ def batch_injection_test(self, freq, orig_response):
58
58
"""
59
59
Uses the batch injection technique to find memcache injections
60
60
"""
61
- # shortcut
61
+ # shortcuts
62
62
send_clean = self ._uri_opener .send_clean
63
+ orig_body = orig_response .get_body ()
63
64
64
- # first checking error response
65
- fake_mutants = create_mutants (freq , ['' , ])
66
-
67
- for mutant in fake_mutants :
65
+ for mutant in create_mutants (freq , ['' ]):
68
66
69
- orig_body = orig_response .get_body ()
70
-
71
- # trying to break normal execution flow with error1 payload
72
- mutant .set_token_value (self .mci .error_1 )
67
+ # trying to break normal execution flow with ERROR_1 payload
68
+ mutant .set_token_value (self .ERROR_1 )
73
69
error_1_response , body_error_1_response = send_clean (mutant )
74
70
75
71
if fuzzy_equal (orig_body , body_error_1_response , self ._eq_limit ):
@@ -81,19 +77,19 @@ def batch_injection_test(self, freq, orig_response):
81
77
82
78
# trying the correct injection request, to confirm that we've found
83
79
# it!
84
-
85
- mutant .set_token_value (self .mci .ok )
80
+ mutant .set_token_value (self .OK )
86
81
ok_response , body_ok_response = send_clean (mutant )
87
82
88
- if fuzzy_not_equal (orig_body , body_ok_response , self ._eq_limit ):
83
+ if fuzzy_equal (body_error_1_response , body_ok_response ,
84
+ self ._eq_limit ):
89
85
#
90
- # now requests should be equal, otherwise injection failed!
86
+ # The "OK" and "ERROR_1" responses are equal, this means that
87
+ # we're not in a memcached injection
91
88
#
92
89
continue
93
90
94
- # error2 request to just make sure that wasn't random bytes
95
-
96
- mutant .set_token_value (self .mci .error_2 )
91
+ # ERROR_2 request to just make sure that we're in a memcached case
92
+ mutant .set_token_value (self .ERROR_2 )
97
93
error_2_response , body_error_2_response = send_clean (mutant )
98
94
99
95
if fuzzy_equal (orig_body , body_error_2_response , self ._eq_limit ):
@@ -107,24 +103,18 @@ def batch_injection_test(self, freq, orig_response):
107
103
ok_response .id ,
108
104
error_2_response .id ]
109
105
110
- desc = 'Memcache injection was found at: "%s", using' \
111
- ' HTTP method %s. The injectable parameter is: "%s"'
112
- desc = desc % (mutant .get_url (),
113
- mutant .get_method (),
114
- mutant .get_token_name ())
106
+ desc = ( 'Memcache injection was found at: "%s", using'
107
+ ' HTTP method %s. The injectable parameter is: "%s"' )
108
+ desc %= (mutant .get_url (),
109
+ mutant .get_method (),
110
+ mutant .get_token_name ())
115
111
116
112
v = Vuln .from_mutant ('Memcache injection vulnerability' , desc ,
117
113
severity .HIGH , response_ids , 'memcachei' ,
118
114
mutant )
119
115
120
- v ['ok_html' ] = ok_response .get_body ()
121
- v ['error_1_html' ] = error_1_response .get_body ()
122
- v ['error_2_html' ] = error_2_response .get_body ()
123
-
124
116
self .kb_append_uniq (self , 'memcachei' , v )
125
117
126
- return
127
-
128
118
def get_long_desc (self ):
129
119
"""
130
120
:return: A DETAILED description of the plugin functions and features.
0 commit comments