@@ -47,32 +47,19 @@ def set_context_and_lifecycle(url, host=None):
4747 context .set_as_current_context ()
4848
4949
50- def ssrf_check (monkeypatch , url ):
50+ def ssrf_check (monkeypatch , url , requests_only = False ):
5151 reset_comms ()
5252 set_context_and_lifecycle (url )
5353 monkeypatch .setenv ("AIKIDO_BLOCK" , "1" )
5454 with pytest .raises (AikidoSSRF ):
5555 requests .get (url )
56+ if requests_only :
57+ return
5658 with pytest .raises (AikidoSSRF ):
5759 http = urllib3 .PoolManager ()
5860 http .request ("GET" , url )
5961
6062
61- """
62- "http://%31%32%37.%30.%30.%31:4000",
63- "http://ⓛocalhost:4000/",
64- "http://127.1.1.1:4000\@127.0.0.1:4000/",
65- "http://127.1.1.1:4000:\@@127.0.0.1:4000/",
66- "http://127.0.0.1:4000#\@127.2.2.2:80/ ",
67- "http://127.1.1.1:4000\\ @127.0.0.1:4000/",
68- "http://127.1.1.1:4000\\ \@127.0.0.1:4000/",
69- "http://127.1.1.1:4000\\ \\ @127.0.0.1:4000/",
70- "http://127.1.1.1:4000\\ \\ \\ \\ \@127.0.0.1:4000/",
71- "http://127.1.1.1:4000∖\\ @127.0.0.1:4000/"
72- "http://1.1.1.1 &@127.0.0.1:4000# @3.3.3.3/",
73- """
74-
75-
7663@pytest .mark .parametrize (
7764 "url" ,
7865 [
@@ -104,30 +91,10 @@ def ssrf_check(monkeypatch, url):
10491 "http://[0000:0000:0000:0000:0000:0000:0000:0001]:8081/test" ,
10592 # private ips written differently
10693 "http://2130706433:8081" ,
107- "http://0x7f000001:8081/" ,
108- # "http://0177.0.0.01:8081/",
94+ "http://0x7f000001:8081/" ,
10995 "http://0x7f.0x0.0x0.0x1:8081/" ,
11096 # 127.0.0.1 ipv6 mapped
11197 "http://[::ffff:127.0.0.1]:8081" ,
112- ## Filter
113- # "http://localhost:4000 /", -> failed to parse
114- # Fix :
115- "http://127%2E0%2E0%2E1:4000" ,
116- # "h\tt\nt\rp://l\to\nc\ra\tl\nh\ro\ts\nt:4\t0\n0\r0/p\ta\nt\rh?q\tu\ne\rry#f\tr\na\rg",
117- # "http://%30:4000",
118- # AWS metadata service
119- # "http://169.254.169.254/latest/meta-data/iam/security-credentials/",
120- "http://0251.0376.0251.0376/latest/meta-data/iam/security-credentials/" ,
121- "http://[fd00:0ec2:0000:0000:0000:0000:0000:0254]:7000/latest/meta-data/iam/security-credentials/" ,
122- "http://0xa9.0xfe.0xa9.0xfe/latest/meta-data/iam/security-credentials/" ,
123- # "http://0251.0376.0124776/latest/meta-data/iam/security-credentials/", -> continous loading
124- "http://0xA9FEA9FE/latest/meta-data/iam/security-credentials/" ,
125- "http://2852039166/latest/meta-data/iam/security-credentials/" ,
126- "http://[::ffff:169.254.169.254]:8081/latest/meta-data/iam/security-credentials/" ,
127- "http://[fd00:ec2::254]/latest/meta-data/iam/security-credentials/" ,
128- # "http://169.254.169.254 &@2.2.2.2# @3.3.3.3/latest/meta-data/iam/security-credentials/", -> continous loading
129- "http://1.1.1.1 &@169.254.169.254# @3.3.3.3/latest/meta-data/iam/security-credentials/" ,
130- # "http://1.1.1.1 &@2.2.2.2# @169.254.169.254/latest/meta-data/iam/security-credentials/", -> continous loading
13198 ],
13299)
133100def test_ssrf_1 (monkeypatch , url ):
@@ -221,5 +188,10 @@ def test_srrf_with_request_to_itself_urllib3(monkeypatch):
221188 http .request ("GET" , "https://localhost/test/4" )
222189
223190
224- def test_ssrf_2 (monkeypatch ):
225- ssrf_check (monkeypatch , "http://127%2E0%2E0%2E1:4000" )
191+ def test_ssrf (monkeypatch ):
192+ ssrf_check (monkeypatch , "http://0177.0.0.01:8081/" , requests_only = True )
193+
194+
195+ def test_ssrf_encoded_chars (monkeypatch ):
196+ # This type of URL only works for requests
197+ ssrf_check (monkeypatch , "http://127%2E0%2E0%2E1:4000" , requests_only = True )
0 commit comments