1+ using System . Net . Sockets ;
2+ using System . Data . SqlClient ;
3+
4+ namespace My . Qltest
5+ {
6+ public class Test
7+ {
8+ private TestSources Sources = new TestSources ( ) ;
9+
10+ //private ILogger Logger => throw null;
11+ private SqlConnection Connection => throw null ;
12+
13+ private string BytesToString ( byte [ ] bytes )
14+ {
15+ // Encode bytes to a UTF8 string.
16+ return System . Text . Encoding . UTF8 . GetString ( bytes ) ;
17+ }
18+
19+ public void M1 ( )
20+ {
21+ // Only a source if "remote" is a selected threat model.
22+ // This is included in the "default" threat model.
23+ using TcpClient client = new TcpClient ( "localhost" , 1234 ) ;
24+ using NetworkStream stream = client . GetStream ( ) ;
25+ byte [ ] buffer = new byte [ 1024 ] ;
26+ int bytesRead = stream . Read ( buffer , 0 , buffer . Length ) ;
27+
28+ // SQL sink
29+ var command = new SqlCommand ( "SELECT * FROM Users WHERE Username = '" + BytesToString ( buffer ) + "'" , Connection ) ;
30+ }
31+
32+ public void M2 ( )
33+ {
34+ // Only a source if "database" is a selected threat model.
35+ string result = Sources . ExecuteQuery ( "SELECT * FROM foo" ) ;
36+
37+ // SQL sink
38+ var command = new SqlCommand ( "SELECT * FROM Users WHERE Username = '" + result + "'" , Connection ) ;
39+ }
40+
41+ public void M3 ( )
42+ {
43+ // Only a source if "environment" is a selected threat model.
44+ string result = Sources . ReadEnv ( "foo" ) ;
45+
46+ // SQL sink
47+ var command = new SqlCommand ( "SELECT * FROM Users WHERE Username = '" + result + "'" , Connection ) ;
48+
49+ }
50+
51+ public void M4 ( )
52+ {
53+ // Only a source if "custom" is a selected threat model.
54+ string result = Sources . GetCustom ( "foo" ) ;
55+
56+ // SQL sink
57+ var command = new SqlCommand ( "SELECT * FROM Users WHERE Username = '" + result + "'" , Connection ) ;
58+ }
59+
60+ public void M5 ( )
61+ {
62+ // Only a source if "commandargs" is a selected threat model.
63+ string result = Sources . GetCliArg ( 0 ) ;
64+
65+ // SQL sink
66+ var command = new SqlCommand ( "SELECT * FROM Users WHERE Username = '" + result + "'" , Connection ) ;
67+ }
68+ }
69+ }
0 commit comments