Skip to content

Commit b6e7159

Browse files
authored
Merge pull request #15 from hangga/devel-deeper-scanning
Devel deeper scanning
2 parents f01820d + ab449e2 commit b6e7159

File tree

8 files changed

+1979
-16
lines changed

8 files changed

+1979
-16
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,14 @@ Add the plugin to your Gradle project.
8080
### KTS
8181
```kotlin
8282
plugins {
83-
id("io.github.hangga.delvelin") version "0.1.1-beta"
83+
id("io.github.hangga.delvelin") version "0.1.2-beta"
8484
}
8585
```
8686

8787
### Groovy
8888
```groovy
8989
plugins {
90-
id 'io.github.hangga.delvelin' version '0.1.1-beta'
90+
id 'io.github.hangga.delvelin' version '0.1.2-beta'
9191
}
9292
```
9393

@@ -153,7 +153,7 @@ repositories {
153153
}
154154

155155
dependencies {
156-
testImplementation('io.github.hangga:delvelin-plugin:0.1.1-beta')
156+
testImplementation('io.github.hangga:delvelin-plugin:0.1.2-beta')
157157
}
158158
```
159159

@@ -169,7 +169,7 @@ dependencies {
169169
<dependency>
170170
<groupId>io.github.hangga</groupId>
171171
<artifactId>delvelin-plugin</artifactId>
172-
<version>0.1.1-beta</version>
172+
<version>0.1.2-beta</version>
173173
<scope>test</scope>
174174
</dependency>
175175
```

src/main/java/io/github/hangga/delvelin/cwedetectors/GeneralScanner.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ public class GeneralScanner {
2020
new SQLInjectionDetector(),
2121
new CmdInjectionDetector(),
2222
new WeakCryptographicDetector(),
23+
new InsecureHttpDetector(),
2324
new OsvDetector()
2425
// add new detector here
2526
);

src/main/java/io/github/hangga/delvelin/cwedetectors/HardCodedSecretDetector.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
public class HardCodedSecretDetector extends BaseDetector {
1111

12-
String msg = "Warning: Potential hardcoded secrets or credentials found in the source code. Hardcoding sensitive information such as passwords, tokens, " +
12+
String msg = "Warning: Hardcoded secrets or credentials found in the source code. Hardcoding sensitive information such as passwords, tokens, " +
1313
"and API keys can expose secrets and increase the risk of data leaks.";
1414

1515
private static final Pattern KEYWORD_PATTERN = Pattern.compile(

src/main/java/io/github/hangga/delvelin/cwedetectors/InsecureHttpDetector.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,11 @@ public void detect(String line, int lineNumber) {
1919
if (!this.extName.equals(".kt") && !this.extName.equals(".java")) {
2020
return;
2121
}
22-
if (line.contains("HttpURLConnection")) {
23-
if (line.contains("http://") || containsHttpUrl(line) || HTTP_URL_PATTERN.matcher(line)
24-
.find()) {
25-
setValidVulnerability(specificLocation(lineNumber), line, "Insecure HTTP detected");
26-
}
22+
23+
if (line.contains("HttpURLConnection") ||
24+
HTTP_URL_PATTERN.matcher(line).find() ||
25+
containsHttpUrl(line)) {
26+
setValidVulnerability(specificLocation(lineNumber), line, "Weak SSL Context configuration. Ensure SSLContext is configured securely.");
2727
}
2828
}
2929

src/main/java/io/github/hangga/delvelin/properties/Config.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,5 @@ public class Config {
99

1010
public static OutputFileFormat outputFileFormat = OutputFileFormat.LOG;
1111

12-
public static String VERSION = "0.1.1-beta";
12+
public static String VERSION = "0.1.2-beta";
1313
}

src/main/java/io/github/hangga/delvelin/properties/Vulnerabilities.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ public String getCweCode() {
3737
}
3838

3939
Vulnerabilities(String description, String cweCode, String priority) {
40-
this.description = "Potential " + description;
40+
this.description = description;
4141
this.cweCode = cweCode;
4242
this.priority = priority;
4343
}
Lines changed: 98 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,108 @@
11
import io.github.hangga.delvelin.Delvelin
22
import io.github.hangga.delvelin.properties.OutputFileFormat
33
import org.junit.jupiter.api.Test
4+
import java.io.BufferedReader
5+
import java.io.InputStreamReader
6+
import java.net.HttpURLConnection
7+
import java.net.URL
8+
import java.security.KeyStore
9+
import javax.net.ssl.HttpsURLConnection
10+
import javax.net.ssl.SSLContext
11+
import javax.net.ssl.TrustManagerFactory
412

513
class DelvelinUnitTest {
14+
615
@Test
716
fun `vulnerability test`() {
8-
Delvelin()
9-
.setOutputFormat(OutputFileFormat.HTML)
10-
.setAllowedExtensions(".gradle",".kts",".java",".kt")
11-
.setAutoLaunchBrowser(true)
17+
Delvelin().setOutputFormat(OutputFileFormat.HTML)
18+
.setAllowedExtensions(".gradle", ".kts", ".java", ".kt").setAutoLaunchBrowser(true)
1219
.scan()
1320
}
21+
22+
@Test
23+
fun `example of insecure Http connection`() {
24+
val urlString = "http://example.com" // Menggunakan HTTP tanpa enkripsi
25+
val url = URL(urlString)
26+
val connection = url.openConnection() as HttpURLConnection
27+
28+
try {
29+
connection.requestMethod = "GET"
30+
connection.connectTimeout = 5000
31+
connection.readTimeout = 5000
32+
connection.doInput = true
33+
34+
val responseCode = connection.responseCode
35+
println("Response Code: $responseCode")
36+
37+
if (responseCode == HttpURLConnection.HTTP_OK) {
38+
val reader = BufferedReader(InputStreamReader(connection.inputStream))
39+
val response = StringBuilder()
40+
var line: String?
41+
42+
while (reader.readLine().also { line = it } != null) {
43+
response.append(line)
44+
}
45+
46+
reader.close()
47+
println("Response: $response")
48+
} else {
49+
println("Failed to connect: $responseCode")
50+
}
51+
} catch (e: Exception) {
52+
e.printStackTrace()
53+
} finally {
54+
connection.disconnect()
55+
}
56+
}
57+
58+
@Test
59+
fun `example of secure Https connection`() {
60+
val urlString = "https://example.com" // URL menggunakan HTTPS
61+
val url = URL(urlString)
62+
63+
// Membuka koneksi HTTPS
64+
val connection = url.openConnection() as HttpsURLConnection
65+
66+
try {
67+
// Menentukan properti koneksi
68+
connection.requestMethod = "GET"
69+
connection.connectTimeout = 5000
70+
connection.readTimeout = 5000
71+
connection.doInput = true
72+
73+
// Validasi sertifikat (gunakan TrustManager untuk pengaturan lebih lanjut jika perlu)
74+
val trustManagerFactory =
75+
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm())
76+
val keyStore = KeyStore.getInstance(KeyStore.getDefaultType())
77+
keyStore.load(null, null)
78+
trustManagerFactory.init(keyStore)
79+
80+
val sslContext = SSLContext.getInstance("TLS")
81+
sslContext.init(null, trustManagerFactory.trustManagers, null)
82+
connection.sslSocketFactory = sslContext.socketFactory
83+
84+
// Mendapatkan response code dan membaca data
85+
val responseCode = connection.responseCode
86+
println("Response Code: $responseCode")
87+
88+
if (responseCode == HttpsURLConnection.HTTP_OK) {
89+
val reader = BufferedReader(InputStreamReader(connection.inputStream))
90+
val response = StringBuilder()
91+
var line: String?
92+
93+
while (reader.readLine().also { line = it } != null) {
94+
response.append(line)
95+
}
96+
97+
reader.close()
98+
println("Response: $response")
99+
} else {
100+
println("Failed to connect: $responseCode")
101+
}
102+
} catch (e: Exception) {
103+
e.printStackTrace()
104+
} finally {
105+
connection.disconnect()
106+
}
107+
}
14108
}

0 commit comments

Comments
 (0)