Skip to content

Commit 7ac4f46

Browse files
committed
Minor improvements for memcached injection andresriancho#4406 , tests can now be run at CI using docker compose + memcached docker image
1 parent 6594b00 commit 7ac4f46

File tree

3 files changed

+32
-38
lines changed

3 files changed

+32
-38
lines changed

w3af/plugins/audit/memcachei.py

Lines changed: 23 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -25,23 +25,23 @@
2525

2626
from w3af.core.controllers.plugins.audit_plugin import AuditPlugin
2727
from w3af.core.controllers.misc.fuzzy_string_cmp import fuzzy_equal
28-
from w3af.core.controllers.misc.fuzzy_string_cmp import fuzzy_not_equal
2928
from w3af.core.controllers.exceptions import HTTPRequestException
3029
from w3af.core.data.fuzzer.fuzzer import create_mutants
3130
from w3af.core.data.kb.vuln import Vuln
3231

3332

34-
MemcacheInjection = namedtuple('MemcacheInjection', ['ok', 'error_1', 'error_2'])
33+
MemcacheInjection = namedtuple('MemcacheInjection',
34+
['ok', 'error_1', 'error_2'])
3535

3636

3737
class memcachei(AuditPlugin):
3838

39+
OK = u'key1 0 30 1\r\n1\r\nset injected 0 10 10\r\n1234567890\r\n'
40+
ERROR_1 = u'key1 0 f 1\r\n1\r\n'
41+
ERROR_2 = u'key1 0 30 0\r\n1\r\n'
42+
3943
def __init__(self):
4044
AuditPlugin.__init__(self)
41-
self.mci = MemcacheInjection(u'key1 0 30 1\r\n1\r\n'
42-
u'set injected 0 10 10\r\n1234567890\r\n',
43-
u'key1 0 f 1\r\n1\r\n',
44-
u'key1 0 30 0\r\n1\r\n')
4545
self._eq_limit = 0.97
4646

4747
def audit(self, freq, orig_response):
@@ -58,18 +58,14 @@ def batch_injection_test(self, freq, orig_response):
5858
"""
5959
Uses the batch injection technique to find memcache injections
6060
"""
61-
# shortcut
61+
# shortcuts
6262
send_clean = self._uri_opener.send_clean
63+
orig_body = orig_response.get_body()
6364

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, ['']):
6866

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)
7369
error_1_response, body_error_1_response = send_clean(mutant)
7470

7571
if fuzzy_equal(orig_body, body_error_1_response, self._eq_limit):
@@ -81,19 +77,19 @@ def batch_injection_test(self, freq, orig_response):
8177

8278
# trying the correct injection request, to confirm that we've found
8379
# it!
84-
85-
mutant.set_token_value(self.mci.ok)
80+
mutant.set_token_value(self.OK)
8681
ok_response, body_ok_response = send_clean(mutant)
8782

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):
8985
#
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
9188
#
9289
continue
9390

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)
9793
error_2_response, body_error_2_response = send_clean(mutant)
9894

9995
if fuzzy_equal(orig_body, body_error_2_response, self._eq_limit):
@@ -107,24 +103,18 @@ def batch_injection_test(self, freq, orig_response):
107103
ok_response.id,
108104
error_2_response.id]
109105

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())
115111

116112
v = Vuln.from_mutant('Memcache injection vulnerability', desc,
117113
severity.HIGH, response_ids, 'memcachei',
118114
mutant)
119115

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-
124116
self.kb_append_uniq(self, 'memcachei', v)
125117

126-
return
127-
128118
def get_long_desc(self):
129119
"""
130120
:return: A DETAILED description of the plugin functions and features.

w3af/plugins/tests/audit/test_memcachei.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
along with w3af; if not, write to the Free Software
1919
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
2020
"""
21-
22-
from nose.plugins.attrib import attr
2321
from w3af.plugins.tests.helper import PluginTest, PluginConfig
2422
from w3af.core.controllers.ci.moth import get_moth_http
2523

@@ -37,13 +35,14 @@ class TestMemcachei(PluginTest):
3735
}
3836
}
3937

40-
@attr('ci_fails')
4138
def test_found_memcachei(self):
4239
cfg = self._run_configs['cfg']
4340
self._scan(cfg['target'], cfg['plugins'])
41+
4442
vulns = self.kb.get('memcachei', 'memcachei')
4543
self.assertEquals(1, len(vulns))
46-
# Now some tests around specific details of the found vuln
4744
vuln = vulns[0]
48-
self.assertEquals("Memcache injection vulnerability", vuln.get_name())
45+
46+
# Now some tests around specific details of the found vuln
47+
self.assertEquals('Memcache injection vulnerability', vuln.get_name())
4948
self.assertEquals(self.target_url, str(vuln.get_url()))

w3af/tests/docker-compose.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@ moth:
33
ports:
44
- "8000:8000"
55
- "8001:8001"
6+
links:
7+
- cache
8+
9+
cache:
10+
image: memcached
611

712

813
wivet:

0 commit comments

Comments
 (0)