APISan: Sanitizing API Usages through Semantic Cross-checking
Insu Yun, Changwoo Min, Xujie Si, Yeongjin Jang, Taesoo Kim, Mayur Naik Georgia Institute of Technology
1
APISan: Sanitizing API Usages through Semantic Cross-checking Insu - - PowerPoint PPT Presentation
APISan: Sanitizing API Usages through Semantic Cross-checking Insu Yun, Changwoo Min, Xujie Si, Yeongjin Jang, Taesoo Kim, Mayur Naik Georgia Institute of Technology 1 APIs in todays software are plentiful yet complex Example: OpenSSL
Insu Yun, Changwoo Min, Xujie Si, Yeongjin Jang, Taesoo Kim, Mayur Naik Georgia Institute of Technology
1
3841 APIs in [v1.0.2h]
+123 APIs)
158 APIs of OpenSSL
2
3
4
5
6
7
8
9
10
11
APISan Majority uses ( Likely correct ) Deviant uses ( Likely bug)
curl curl curl nmap curl nginx nginx curl nmap nginx curl hexchat
12
APISan Majority uses ( Likely correct ) Deviant uses ( Likely bug)
curl curl curl nmap curl nginx nginx curl nmap nginx curl hexchat
13
APISan Majority uses ( Likely correct ) Deviant uses ( Likely bug)
curl curl curl nmap curl nginx nginx curl nmap nginx curl hexchat
14
APISan Majority uses ( Likely correct ) Deviant uses ( Likely bug)
curl curl curl nmap curl nginx nginx curl nmap nginx curl hexchat
15
16
17
no peer ce certificate à alw always retu turns X509_V_ V_OK OK
18
no peer ce certificate à alw always retu turns X509_V_ V_OK OK
19
20
21
22
23
24
25
26
Correct
27
cert = SSL_get_peer_certificate(handle); if (!cert) {…} err = SSL_get_verify_result(handle); if (err == X509_V_OK) { … } cu curl if (SSL_get_verify_result(conn) != X509_V_OK) return NGX_OK; cert = SSL_get_peer_certificate(conn); if (cert) { … } ng ngin inx cert = SSL_get_peer_certificate(ssl); if (cert == NULL) return 0; if (SSL_get_verify_result(ssl) != X509_V_OK) {…} nmap nmap err = SSL_get_verify_result(ssl); switch(err) { case X509_V_OK: cert = SSL_get_peer_certificate(ssl); he hexcha hat
Correct
28
cert = SSL_get_peer_certificate(handle); if (!cert) {…} err = SSL_get_verify_result(handle); if (err == X509_V_OK) { … } cu curl if (SSL_get_verify_result(conn) != X509_V_OK) return NGX_OK; cert = SSL_get_peer_certificate(conn); if (cert) { … } ng ngin inx cert = SSL_get_peer_certificate(ssl); if (cert == NULL) return 0; if (SSL_get_verify_result(ssl) != X509_V_OK) {…} nmap nmap err = SSL_get_verify_result(ssl); switch(err) { case X509_V_OK: cert = SSL_get_peer_certificate(ssl); he hexcha hat
Correct
29
cert = SSL_get_peer_certificate(handle); if (!cert) {…} err = SSL_get_verify_result(handle); if (err == X509_V_OK) { … } cu curl if (SSL_get_verify_result(conn) != X509_V_OK) return NGX_OK; cert = SSL_get_peer_certificate(conn); if (cert) { … } ng ngin inx cert = SSL_get_peer_certificate(ssl); if (cert == NULL) return 0; if (SSL_get_verify_result(ssl) != X509_V_OK) {…} nmap nmap err = SSL_get_verify_result(ssl); switch(err) { case X509_V_OK: cert = SSL_get_peer_certificate(ssl); he hexcha hat
Correct Correct
30
cert = SSL_get_peer_certificate(handle); if (!cert) {…} err = SSL_get_verify_result(handle); if (err == X509_V_OK) { … } cu curl if (SSL_get_verify_result(conn) != X509_V_OK) return NGX_OK; cert = SSL_get_peer_certificate(conn); if (cert) { … } ng ngin inx cert = SSL_get_peer_certificate(ssl); if (cert == NULL) return 0; if (SSL_get_verify_result(ssl) != X509_V_OK) {…} nmap nmap err = SSL_get_verify_result(ssl); switch(err) { case X509_V_OK: cert = SSL_get_peer_certificate(ssl); he hexcha hat
Correct Correct
31
cert = SSL_get_peer_certificate(handle); if (!cert) {…} err = SSL_get_verify_result(handle); if (err == X509_V_OK) { … } cu curl if (SSL_get_verify_result(conn) != X509_V_OK) return NGX_OK; cert = SSL_get_peer_certificate(conn); if (cert) { … } ng ngin inx cert = SSL_get_peer_certificate(ssl); if (cert == NULL) return 0; if (SSL_get_verify_result(ssl) != X509_V_OK) {…} nmap nmap err = SSL_get_verify_result(ssl); switch(err) { case X509_V_OK: cert = SSL_get_peer_certificate(ssl); he hexcha hat
Correct Correct Correct
32
cert = SSL_get_peer_certificate(handle); if (!cert) {…} err = SSL_get_verify_result(handle); if (err == X509_V_OK) { … } cu curl if (SSL_get_verify_result(conn) != X509_V_OK) return NGX_OK; cert = SSL_get_peer_certificate(conn); if (cert) { … } ng ngin inx cert = SSL_get_peer_certificate(ssl); if (cert == NULL) return 0; if (SSL_get_verify_result(ssl) != X509_V_OK) {…} nmap nmap err = SSL_get_verify_result(ssl); switch(err) { case X509_V_OK: cert = SSL_get_peer_certificate(ssl); he hexcha hat
Correct Correct Correct
// // if (cer cert) is missed ed
33
cert = SSL_get_peer_certificate(handle); if (!cert) {…} err = SSL_get_verify_result(handle); if (err == X509_V_OK) { … } cu curl if (SSL_get_verify_result(conn) != X509_V_OK) return NGX_OK; cert = SSL_get_peer_certificate(conn); if (cert) { … } ng ngin inx cert = SSL_get_peer_certificate(ssl); if (cert == NULL) return 0; if (SSL_get_verify_result(ssl) != X509_V_OK) {…} nmap nmap err = SSL_get_verify_result(ssl); switch(err) { case X509_V_OK: cert = SSL_get_peer_certificate(ssl); he hexcha hat
Correct Correct Correct Incorrect
// // if (cer cert) is missed ed
34
cert = SSL_get_peer_certificate(handle); if (!cert) {…} err = SSL_get_verify_result(handle); if (err == X509_V_OK) { … } cu curl if (SSL_get_verify_result(conn) != X509_V_OK) return NGX_OK; cert = SSL_get_peer_certificate(conn); if (cert) { … } ng ngin inx cert = SSL_get_peer_certificate(ssl); if (cert == NULL) return 0; if (SSL_get_verify_result(ssl) != X509_V_OK) {…} nmap nmap err = SSL_get_verify_result(ssl); switch(err) { case X509_V_OK: cert = SSL_get_peer_certificate(ssl); he hexcha hat
Correct Correct Correct Incorrect
// // if (cer cert) is missed ed
35
cert = SSL_get_peer_certificate(handle); if (!cert) {…} err = SSL_get_verify_result(handle); if (err == X509_V_OK) { … } cu curl if (SSL_get_verify_result(conn) != X509_V_OK) return NGX_OK; cert = SSL_get_peer_certificate(conn); if (cert) { … } ng ngin inx cert = SSL_get_peer_certificate(ssl); if (cert == NULL) return 0; if (SSL_get_verify_result(ssl) != X509_V_OK) {…} nmap nmap err = SSL_get_verify_result(ssl); switch(err) { case X509_V_OK: cert = SSL_get_peer_certificate(ssl); he hexcha hat // // if (cer cert) is missed ed
Correct Correct Correct Incorrect
36
cert = SSL_get_peer_certificate(handle); if (!cert) {…} err = SSL_get_verify_result(handle); if (err == X509_V_OK) { … } cu curl if (SSL_get_verify_result(conn) != X509_V_OK) return NGX_OK; cert = SSL_get_peer_certificate(conn); if (cert) { … } ng ngin inx cert = SSL_get_peer_certificate(ssl); if (cert == NULL) return 0; if (SSL_get_verify_result(ssl) != X509_V_OK) {…} nmap nmap err = SSL_get_verify_result(ssl); switch(err) { case X509_V_OK: cert = SSL_get_peer_certificate(ssl); he hexcha hat // // if (cer cert) is missed ed
Correct Correct Correct Incorrect
37
38
cert = SSL_get_peer_certificate(handle); if (!cert) {…} ... len = BIO_get_mem_data(mem, (char **) &ptr); infof(data, " start date: %.*s\n", len, ptr); rc = BIO_reset(mem); … err = SSL_get_verify_result(handle); if (err == X509_V_OK) { … } cu curl cert = SSL_get_peer_certificate(handle); if (!cert) {…} err = SSL_get_verify_result(handle); if (err == X509_V_OK) { … } cu curl (simplified ed)
39
Source code Source code Source code
40
Source code Source code Source code APIs Arguments Constraints Symbolic execution database Relaxed Symbolic Execution
41
Return value checker Argument checker Causality checker Condition checker 4 4 Ch Checkers Source code Source code Source code APIs Arguments Constraints Symbolic execution database Relaxed Symbolic Execution
42
Return value checker Argument checker Causality checker Condition checker 4 4 Ch Checkers Source code Source code Source code APIs Arguments Constraints Symbolic execution database Relaxed Symbolic Execution
: minor, but not bug : minor and bug
…
Minority uses
43
Return value checker Argument checker Causality checker Condition checker 4 4 Ch Checkers Source code Source code Source code APIs Arguments Constraints Symbolic execution database Relaxed Symbolic Execution
: minor, but not bug : minor and bug
…
Minority uses
...
Ranked minority uses
44
Return value checker Argument checker Causality checker Condition checker 4 4 Ch Checkers Source code Source code Source code APIs Arguments Constraints Symbolic execution database Relaxed Symbolic Execution
: minor, but not bug : minor and bug
…
Minority uses
...
Ranked minority uses
45
46
cert = SSL_get_peer_certificate(handle); if (!cert) {…} err = SSL_get_verify_result(handle); if (err != X509_V_OK) { … }
47
for(…) { cert = SSL_get_peer_certificate(handle); if (!cert) {…} err = SSL_get_verify_result(handle); if (err != X509_V_OK) { … } }
48
cert != NULL ∧ err == X509_V_OK cert = {[-MAX, -1] , [1, MAX]} err = {[X509_V_OK, X509_V_OK]}
49
50
cert = SSL_get_peer_certificate(handle); if if (!cert) {…} err = SSL_get_verify_result(handle); if if (err == X509_V_OK) { … } So Source ce co code Sy Symbolic abstractions
51
Call SSL_get_peer_certificate(handle) cert = SSL_get_peer_certificate(handle); if if (!cert) {…} err = SSL_get_verify_result(handle); if if (err == X509_V_OK) { … } So Source ce co code Sy Symbolic abstractions
52
Call SSL_get_peer_certificate(handle) Constraint SSL_get_peer_certificate(handle) = {[-MAX, -1], [1, MAX]} cert = SSL_get_peer_certificate(handle); if if (!cert) {…} err = SSL_get_verify_result(handle); if if (err == X509_V_OK) { … } So Source ce co code Sy Symbolic abstractions
53
Call SSL_get_peer_certificate(handle) Constraint SSL_get_peer_certificate(handle) = {[-MAX, -1], [1, MAX]} Call SSL_get_verify_result(handle) cert = SSL_get_peer_certificate(handle); if if (!cert) {…} err = SSL_get_verify_result(handle); if if (err == X509_V_OK) { … } So Source ce co code Sy Symbolic abstractions
54
Call SSL_get_peer_certificate(handle) Constraint SSL_get_peer_certificate(handle) = {[-MAX, -1], [1, MAX]} Call SSL_get_verify_result(handle) Constraint SSL_get_verify_result(handle) = {[X509_V_OK, X509_V_OK]} cert = SSL_get_peer_certificate(handle); if if (!cert) {…} err = SSL_get_verify_result(handle); if if (err == X509_V_OK) { … } So Source ce co code Sy Symbolic abstractions
55
cert = SSL_get_peer_certificate(handle); if if (!cert) {…} err = SSL_get_verify_result(handle); if if (err == X509_V_OK) { … } So Source ce code
56
cert = SSL_get_peer_certificate(handle); if if (!cert) {…} err = SSL_get_verify_result(handle); if if (err == X509_V_OK) { … } So Source ce code
Symbolic Abstractions #1
57
cert = SSL_get_peer_certificate(handle); if if (!cert) {…} err = SSL_get_verify_result(handle); if if (err == X509_V_OK) { … } So Source ce code
Symbolic Abstractions #1 Symbolic Abstractions #2
58
cert = SSL_get_peer_certificate(handle); if if (!cert) {…} err = SSL_get_verify_result(handle); if if (err == X509_V_OK) { … } So Source ce code
Symbolic Abstractions #1 …. Symbolic Abstractions #2 Symbolic Abstractions #3
59
Return value checker Argument checker Causality checker Condition checker 4 4 Ch Checkers Source code Source code Source code APIs Arguments Constraints Symbolic execution database Relaxed Symbolic Execution
: minor, but not bug : minor and bug
…
Minority uses
...
Ranked minority uses
60
61
62
63
64
65
66
67
Call SSL_get_peer_certificate(handle) Constraint SSL_get_peer_certificate(handle) = {[-MAX, -1], [1, MAX]} Call SSL_get_verify_result(handle) Constraint SSL_get_verify_result(handle) = {[X509_V_OK, X509_V_OK]} cu curl Event Line SSL_get_verify_result = {[X509_V_OK, X509_V_OK]} {cu curl} Constraint Line SSL_get_peer_certificate = {[-MAX, -1], [1, MAX]} {cu curl} … …. Any constraint
Line numbers when event is called
68
Event Line SSL_get_verify_result = {[X509_V_OK, X509_V_OK]} {curl, ng ngin inx} Constraint Line SSL_get_peer_certificate = {[-MAX, -1], [1, MAX]} {curl, ng ngin inx} … …. Call SSL_get_verify_result(conn) Constraint SSL_get_verify_result(handle) == {[X509_V_OK, X509_V_OK]} Call SSL_get_peer_certificate(conn) Constraint SSL_get_peer_certificate(conn) != {[-MAX, -1], [1, MAX]} ng ngin inx
69
Call SSL_get_peer_certificate(ssl) Constraint SSL_get_peer_certificate(ssl) = {[-MAX, -1], [1, MAX]} Call SSL_get_verify_result(ssl) Constraint SSL_get_verify_result(ssl) = {[X509_V_OK, X509_V_OK]} nmap nmap Event Line SSL_get_verify_result = {[X509_V_OK, X509_V_OK]} {curl, nginx, nmap nmap} Constraint Line SSL_get_peer_certificate = {[-MAX, -1], [1, MAX]} {curl, nginx, nmap nmap} … ….
70
Call SSL_get_verify_result(ssl) Constraint SSL_get_verify_result(ssl) = {[X509_V_OK, X509_V_OK]} Call SSL_get_peer_certificate(ssl) he hexcha hat Event Line SSL_get_verify_result = {[X509_V_OK, X509_V_OK]} {curl, nginx, nmap, he hexcha hat} Constraint Line SSL_get_peer_certificate = {[-MAX, -1], [1, MAX]} {curl, nginx, nmap} … ….
71
Event Line SSL_get_verify_result = {[X509_V_OK, X509_V_OK]} {curl, nginx, nmap, hexchat, …} Constraint Line SSL_get_peer_certificate = {[-MAX, -1], [1, MAX]} {curl, nginx, nmap, …} … ….
72
Event Line SSL_get_verify_result = {[X509_V_OK, X509_V_OK]} {curl, nginx, nmap, hexchat, …} Constraint Line SSL_get_peer_certificate = {[-MAX, -1], [1, MAX]} {curl, nginx, nmap, …} … …. Majority uses ( Likely correct )
73
Event Line SSL_get_verify_result = {[X509_V_OK, X509_V_OK]} {curl, nginx, nmap, hexchat, …} Constraint Line SSL_get_peer_certificate = {[-MAX, -1], [1, MAX]} {curl, nginx, nmap, …} … …. Majority uses ( Likely correct ) Deviant uses ( Likely bug)
= total_event – majority_use = {he
hexcha chat, , …} …}
74
Return value checker Argument checker Causality checker Condition checker 4 4 Ch Checkers Source code Source code Source code APIs Arguments Constraints Symbolic execution database Relaxed Symbolic Execution
: minor, but not bug : minor and bug
…
Minority uses
...
Ranked minority uses
75
76
77
78
79
80
$ $ ap apis isan an ma make # use use existi ting ng bui build d comma mmand nd
$ $ ap apis isan an --
check cker=cp cpair # # cp cpair : causality ch check cker
$ap apis isan an --
check cker=cp cpair --
db=a =app1, app2
81
82
83
with Return Value Checker
84
with Return Value Checker
85
30 30 bugs in 20 20 AP APIs 24 24 bugs in 3 3 AP APIs
with Return Value Checker
86
30 30 bugs in 20 20 AP APIs 24 24 bugs in 3 3 AP APIs 15 bugs in 1 APIs
Generating database : 8 hours Each checker: 6 hours
87
88
89