-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from hangga/devel-deeper-scanning
Devel deeper scanning
- Loading branch information
Showing
8 changed files
with
1,979 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,108 @@ | ||
import io.github.hangga.delvelin.Delvelin | ||
import io.github.hangga.delvelin.properties.OutputFileFormat | ||
import org.junit.jupiter.api.Test | ||
import java.io.BufferedReader | ||
import java.io.InputStreamReader | ||
import java.net.HttpURLConnection | ||
import java.net.URL | ||
import java.security.KeyStore | ||
import javax.net.ssl.HttpsURLConnection | ||
import javax.net.ssl.SSLContext | ||
import javax.net.ssl.TrustManagerFactory | ||
|
||
class DelvelinUnitTest { | ||
|
||
@Test | ||
fun `vulnerability test`() { | ||
Delvelin() | ||
.setOutputFormat(OutputFileFormat.HTML) | ||
.setAllowedExtensions(".gradle",".kts",".java",".kt") | ||
.setAutoLaunchBrowser(true) | ||
Delvelin().setOutputFormat(OutputFileFormat.HTML) | ||
.setAllowedExtensions(".gradle", ".kts", ".java", ".kt").setAutoLaunchBrowser(true) | ||
.scan() | ||
} | ||
|
||
@Test | ||
fun `example of insecure Http connection`() { | ||
val urlString = "http://example.com" // Menggunakan HTTP tanpa enkripsi | ||
val url = URL(urlString) | ||
val connection = url.openConnection() as HttpURLConnection | ||
|
||
try { | ||
connection.requestMethod = "GET" | ||
connection.connectTimeout = 5000 | ||
connection.readTimeout = 5000 | ||
connection.doInput = true | ||
|
||
val responseCode = connection.responseCode | ||
println("Response Code: $responseCode") | ||
|
||
if (responseCode == HttpURLConnection.HTTP_OK) { | ||
val reader = BufferedReader(InputStreamReader(connection.inputStream)) | ||
val response = StringBuilder() | ||
var line: String? | ||
|
||
while (reader.readLine().also { line = it } != null) { | ||
response.append(line) | ||
} | ||
|
||
reader.close() | ||
println("Response: $response") | ||
} else { | ||
println("Failed to connect: $responseCode") | ||
} | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} finally { | ||
connection.disconnect() | ||
} | ||
} | ||
|
||
@Test | ||
fun `example of secure Https connection`() { | ||
val urlString = "https://example.com" // URL menggunakan HTTPS | ||
val url = URL(urlString) | ||
|
||
// Membuka koneksi HTTPS | ||
val connection = url.openConnection() as HttpsURLConnection | ||
|
||
try { | ||
// Menentukan properti koneksi | ||
connection.requestMethod = "GET" | ||
connection.connectTimeout = 5000 | ||
connection.readTimeout = 5000 | ||
connection.doInput = true | ||
|
||
// Validasi sertifikat (gunakan TrustManager untuk pengaturan lebih lanjut jika perlu) | ||
val trustManagerFactory = | ||
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm()) | ||
val keyStore = KeyStore.getInstance(KeyStore.getDefaultType()) | ||
keyStore.load(null, null) | ||
trustManagerFactory.init(keyStore) | ||
|
||
val sslContext = SSLContext.getInstance("TLS") | ||
sslContext.init(null, trustManagerFactory.trustManagers, null) | ||
connection.sslSocketFactory = sslContext.socketFactory | ||
|
||
// Mendapatkan response code dan membaca data | ||
val responseCode = connection.responseCode | ||
println("Response Code: $responseCode") | ||
|
||
if (responseCode == HttpsURLConnection.HTTP_OK) { | ||
val reader = BufferedReader(InputStreamReader(connection.inputStream)) | ||
val response = StringBuilder() | ||
var line: String? | ||
|
||
while (reader.readLine().also { line = it } != null) { | ||
response.append(line) | ||
} | ||
|
||
reader.close() | ||
println("Response: $response") | ||
} else { | ||
println("Failed to connect: $responseCode") | ||
} | ||
} catch (e: Exception) { | ||
e.printStackTrace() | ||
} finally { | ||
connection.disconnect() | ||
} | ||
} | ||
} |
Oops, something went wrong.