-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Expand file tree
/
Copy pathTest.java
More file actions
72 lines (55 loc) · 2.07 KB
/
Copy pathTest.java
File metadata and controls
72 lines (55 loc) · 2.07 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
67
68
69
70
71
72
import java.sql.*;
import java.net.*;
import java.util.logging.*;
import java.nio.charset.StandardCharsets;
import testlib.TestSources;
class Test {
private TestSources sources = new TestSources();
private String byteToString(byte[] data) {
return new String(data, StandardCharsets.UTF_8);
}
public void M1(Statement handle) throws Exception {
// Only a source if "remote" is a selected threat model.
// This is included in the "default" threat model.
Socket sock = new Socket("localhost", 1234);
byte[] data = new byte[1024];
sock.getInputStream().read(data);
// Logging sink
Logger.getLogger("foo").severe(byteToString(data));
// SQL sink
handle.executeUpdate("INSERT INTO foo VALUES ('" + byteToString(data) + "')");
}
public void M2(Statement handle) throws Exception {
// Only a source if "database" is a selected threat model.
String result = sources.executeQuery("SELECT * FROM foo");
// SQL sink
handle.executeUpdate("INSERT INTO foo VALUES ('" + result + "')");
// Logging sink
Logger.getLogger("foo").severe(result);
}
public void M3(Statement handle) throws Exception {
// Only a source if "environment" is a selected threat model.
String result = sources.readEnv("MY_ENV_VAR");
// SQL sink
handle.executeUpdate("INSERT INTO foo VALUES ('" + result + "')");
// Logging sink
Logger.getLogger("foo").severe(result);
}
public void M4(Statement handle) throws Exception {
// Only a source if "custom" is a selected threat model.
String result = sources.getCustom("custom");
// SQL sink
handle.executeUpdate("INSERT INTO foo VALUES ('" + result + "')");
// Logging sink
Logger.getLogger("foo").severe(result);
}
public void M5(Statement handle) throws Exception {
// Only a source if "stdin" is a selected threat model.
byte[] data = new byte[1024];
System.in.read(data);
// SQL sink
handle.executeUpdate("INSERT INTO foo VALUES ('" + byteToString(data) + "')");
// Logging sink
Logger.getLogger("foo").severe(byteToString(data));
}
}