-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathinjection.java
More file actions
66 lines (53 loc) · 2.25 KB
/
injection.java
File metadata and controls
66 lines (53 loc) · 2.25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Scanner;
public class injection {
public static void main(String[] args) {
System.out.println("SQL-Injection \n");
System.out.println("Enter your link of the website : ");
String link = new Scanner(System.in).next();
HttpURLConnection httpURLConnection = null;
try {
new URL(link);
link += "%27";
if (!link.contains("?")) {
System.out.println("The website isn’t vulnerable");
}
else {
URL url = new URL(link);
httpURLConnection = (HttpURLConnection) url.openConnection();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpURLConnection.getInputStream()));
String input;
StringBuilder stringBuilder = new StringBuilder();
while ( (input = bufferedReader.readLine()) != null) {
stringBuilder.append(input);
}
String content = stringBuilder.toString();
if (content.contains("mysql_fetch_array()") || content.contains("Exception") || content.contains("missing") || content.length() <=0) {
System.out.println("The website is vulnerable");
}else {
System.out.println("The website isn’t vulnerable");
}
bufferedReader.close();
}
} catch (MalformedURLException e) {
System.out.println("Enter a valid link");
} catch (IOException e) {
assert httpURLConnection != null;
try {
int res_code =httpURLConnection.getResponseCode();
if (res_code == 500) {
System.out.println("The website is vulnerable");
}else {
System.out.println("The website isn’t vulnerable");
}
} catch (IOException e1) {
e1.printStackTrace();
}
}
}
}