Skip to content

Commit 76504ef

Browse files
Merge pull request #197 from AikidoSec/fix-ssrf-bug-with-hostname-capitalization
Fix SSRF bug: Ignore case when comparing hostnames
2 parents e70bcea + d29479f commit 76504ef

3 files changed

Lines changed: 36 additions & 1 deletion

File tree

agent_api/src/main/java/dev/aikido/agent_api/vulnerabilities/ssrf/FindHostnameInContext.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public static boolean hostnameInUserInput(String userInput, String hostname, int
5050
if (userInputUrl == null || userInputUrl.getHost() == null) {
5151
continue;
5252
}
53-
if (userInputUrl.getHost().equals(hostnameUrl.getHost())) {
53+
if (userInputUrl.getHost().equalsIgnoreCase(hostnameUrl.getHost())) {
5454
if (userInputUrl.getPort() == -1 || port == -1) {
5555
return true;
5656
}

agent_api/src/test/java/vulnerabilities/ssrf/FindHostnameInContextTest.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ void testItParsesHostnameFromUserInputWithPathBehindIt() {
3737
assertTrue(hostnameInUserInput("http://localhost/path", "localhost", 80));
3838
}
3939

40+
@Test
41+
void testHostnameCapitalizationIsNotImportant() {
42+
assertTrue(hostnameInUserInput("http://Localhost/path", "localhost", 80));
43+
}
44+
45+
@Test
46+
void testHostnameCapitalizationIsNotImportant2() {
47+
assertTrue(hostnameInUserInput("http://localhost/path", "LOCALHOST", 80));
48+
}
49+
50+
4051
@Test
4152
void testItDoesNotParseHostnameFromUserInputWithMisspelledProtocol() {
4253
assertFalse(hostnameInUserInput("http:/localhost", "localhost", 80));

agent_api/src/test/java/vulnerabilities/ssrf/SSRFDetectorTest.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,30 @@ public void testSsrfDetectorWithRedirectTo127IP() throws MalformedURLException {
6060
assertEquals("8080", attackData.metadata.get("port"));
6161
}
6262

63+
@Test
64+
@SetEnvironmentVariable(key = "AIKIDO_TOKEN", value = "invalid-token")
65+
public void testSsrfDetectorWithRedirectTo127IPButHostnameCapitalizationDifferent() throws MalformedURLException {
66+
// Setup context :
67+
setContextAndLifecycle("http://Ssrf-redirects.testssandbox.com/ssrf-test");
68+
69+
URLCollector.report(new URL("http://Ssrf-redirects.testssandbox.com/ssrf-test"));
70+
RedirectCollector.report(new URL("http://ssrf-Redirects.testssandbox.com/ssrf-test"), new URL("http://127.0.0.1:8080"));
71+
Attack attackData = new SSRFDetector().run(
72+
"127.0.0.1", 8080,
73+
List.of("127.0.0.1"),
74+
"testop"
75+
);
76+
77+
assertNotNull(attackData);
78+
assertEquals("testop", attackData.operation);
79+
assertEquals("ssrf", attackData.kind);
80+
assertEquals("query", attackData.source);
81+
assertEquals("http://Ssrf-redirects.testssandbox.com/ssrf-test", attackData.payload);
82+
assertEquals(".arg.[0]", attackData.pathToPayload);
83+
assertEquals("127.0.0.1", attackData.metadata.get("hostname"));
84+
assertEquals("8080", attackData.metadata.get("port"));
85+
}
86+
6387
@Test
6488
@SetEnvironmentVariable(key = "AIKIDO_TOKEN", value = "invalid-token")
6589
public void testSsrfDetectorWithRedirectToLocalhost() throws MalformedURLException {

0 commit comments

Comments
 (0)