-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathInsecureProtocol.ql
More file actions
60 lines (51 loc) · 1.87 KB
/
InsecureProtocol.ql
File metadata and controls
60 lines (51 loc) · 1.87 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
/**
* @name Use of insecure SSL/TLS version
* @description An insecure version of SSL/TLS has been specified. This may
* leave the connection open to attacks.
* @id py/insecure-protocol
* @kind problem
* @problem.severity warning
* @precision high
* @tags security
* external/cwe/cwe-327
*/
import python
FunctionObject ssl_wrap_socket() {
result = any(ModuleObject ssl | ssl.getName() = "ssl").getAttribute("wrap_socket")
}
string insecure_version_name() {
// For the `ssl` module
result = "SSLv2_METHOD" or
result = "SSLv23_METHOD" or
result = "SSLv3_METHOD" or
result = "TLSv1_METHOD" or
// For `pyOpenSSL.SSL`
result = "PROTOCOL_SSLv2" or
result = "PROTOCOL_SSLv3" or
result = "PROTOCOL_TLSv1"
}
private ModuleObject the_ssl_module() {
result = any(ModuleObject m | m.getName() = "ssl")
}
private ModuleObject the_pyOpenSSL_module() {
result = any(ModuleObject m | m.getName() = "pyOpenSSL").getAttribute("SSL")
}
predicate unsafe_ssl_wrap_method_call(CallNode call) {
call = ssl_wrap_socket().getACall() and
exists(ControlFlowNode arg | arg = call.getArgByName("ssl_version") |
arg.(AttrNode).getObject(insecure_version_name()).refersTo(the_ssl_module())
)
}
ClassObject the_pyOpenSSL_Context_class() {
result = any(ModuleObject m | m.getName() = "pyOpenSSL.SSL").getAttribute("Context")
}
predicate unsafe_pyOpenSSL_Context_call(CallNode call) {
call = the_pyOpenSSL_Context_class().getACall() and
call.getArgByName("method").refersTo(the_pyOpenSSL_module().getAttribute(insecure_version_name()))
}
from CallNode call, string method_name
where
unsafe_ssl_wrap_method_call(call) and method_name = "ssl.wrap_socket"
or
unsafe_pyOpenSSL_Context_call(call) and method_name = "pyOpenSSL.SSL.Context"
select call, "Insecure SSL/TLS protocol version specified in call to " + method_name + "."