Skip to content

Commit ebb5ba5

Browse files
committed
Adds queries for rsyslog's blogpost
1 parent 7a7834b commit ebb5ba5

6 files changed

Lines changed: 91 additions & 0 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import cpp
2+
3+
class ReadFunctionCall extends FunctionCall {
4+
ReadFunctionCall() {
5+
this.getTarget().getName() = "pread" or
6+
this.getTarget().getName() = "read" or
7+
this.getTarget().getName() = "readv" or
8+
this.getTarget().getName() = "recvfrom" or
9+
this.getTarget().getName() = "recvmsg" or
10+
this.getTarget().getName() = "recv"
11+
}
12+
}
13+
14+
from ReadFunctionCall call
15+
select call.getFile(), call.getEnclosingFunction(), call
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import cpp
2+
3+
class RawMessageFieldAccess extends FieldAccess {
4+
RawMessageFieldAccess() {
5+
this.getTarget().getName() = "pszRawMsg"
6+
}
7+
}
8+
9+
class RawMsgAccessFunction extends Function {
10+
RawMsgAccessFunction() {
11+
any(RawMessageFieldAccess access).getEnclosingFunction() = this
12+
}
13+
}
14+
15+
from RawMsgAccessFunction access
16+
select access.getFile(), access
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import cpp
2+
3+
class RawMessageFieldAccess extends FieldAccess {
4+
RawMessageFieldAccess() {
5+
this.getTarget().getName() = "pszRawMsg"
6+
}
7+
}
8+
9+
class RawMsgAccessFunction extends Function {
10+
RawMsgAccessFunction() {
11+
any(RawMessageFieldAccess access).getEnclosingFunction() = this
12+
or
13+
exists(
14+
FunctionCall call |
15+
call.getEnclosingFunction() = this and (
16+
call.getTarget().getName() = "getMSG" or
17+
call.getTarget().getName() = "getRawMsg"
18+
)
19+
)
20+
}
21+
}
22+
23+
from RawMsgAccessFunction access
24+
select access.getFile(), access
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import cpp
2+
3+
class ParseFunction extends Function {
4+
ParseFunction() {
5+
this.getName() = "parse" or
6+
this.getName() = "parse2"
7+
}
8+
}
9+
10+
from ParseFunction parse
11+
select parse.getFile(), parse
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import cpp
2+
import semmle.code.cpp.dataflow.DataFlow
3+
import semmle.code.cpp.dataflow.TaintTracking
4+
5+
class RawMessageFieldAccess extends FieldAccess {
6+
RawMessageFieldAccess() {
7+
this.getTarget().getName() = "pszRawMsg"
8+
}
9+
}
10+
11+
from DataFlow::Node source, DataFlow::Node sink, RawMessageFieldAccess access, WhileStmt loop
12+
where
13+
TaintTracking::localTaint(source, sink) and
14+
source.asExpr() = access and
15+
sink.asExpr() = loop.getCondition().getAChild*()
16+
select "Loop iterates data from:", source, sink
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
# Bug Hunting with CodeQL, an rsyslog Case Study
2+
3+
This repo contains the CodeQL queries used in the [Bug Hunting with CodeQL, an rsyslog Case Study](https://securitylab.github.com/research/bug-hunting-codeql-rsyslog) blog post.
4+
5+
- [Discovering program input](01_find_data_input.ql)
6+
- [Data flow exploration](02_find_data_pointer_usage.ql)
7+
- [Data flow exploration (extended)](03_find_data_pointer_usage_extended.ql)
8+
- [Finding data parsers](04_find_parsers.ql)
9+
- [Finding tainted loops](05_find_tainted_iterations.ql)

0 commit comments

Comments
 (0)