CodeQl lab learn
step-3
query a function named strlen
import cpp
from Function f
where f.getName() = "strlen"
select f, "a function named strlen"
step-4
query a function named memcpy
import cpp
from Function f
where f.getName() = "memcpy"
select f, "a function named memcpy"
step-5
query macros named ntohs or ntohl or ntohll
import cpp
from Macro macro
where macro.getName() = "ntohs"
or macro.getName() = "ntohl"
or macro.getName() = "ntohll"
select macro, "found macro"
more effective
import cpp
from Macro macro
where macro.getName() in ["ntohs", "ntohl", "ntohll"]
select macro, "found macro"
use Regular Expression
import cpp
from Macro macro
where macro.getName().regexpMatch("ntoh(s|l|ll)")
select macro, "found macro"
step-6
query the caller of a function
import cpp
from FunctionCall fc
where fc.getTarget().getName() = "memcpy"
select fc, "caller of the memcpy"
step-7
query the invocations of macros
import cpp
from MacroInvocation mi
where mi.getMacro().getName().regexpMatch("ntoh(s|l|ll)")
select mi
step-8
query the expressions that correspond to macro invocations.
import cpp
from MacroInvocation mi
where mi.getMacro().getName().regexpMatch("ntoh(s|l|ll)")
select mi.getExpr()
step-9
Write your own CodeQL class to represent a set of interesting source code elements
To define a class, you write:
- The keyword class.
- The name of the class. This is an identifier starting with an uppercase letter.
- The supertypes that the class is derived from via extends and/or instanceof
- The body of the class, enclosed in braces.
class OneTwoThree extends int {
OneTwoThree() { // characteristic predicate
this = 1 or this = 2 or this = 3
}
string getAString() { // member predicate
result = "One, two or three: " + this.toString()
}
predicate isEven() { // member predicate
this = 2
}
}
import cpp
/**
* An expression involved when swapping the byte order of network data.
* Its value is likely to have been read from the network.
*/
class NetworkByteSwap extends Expr {
NetworkByteSwap() {
exists(MacroInvocation mi |
mi.getMacroName().regexpMatch("ntoh(s|l|ll)") and
this = mi.getExpr()
)
}
}
from NetworkByteSwap n
select n
step-10
query to track the flow of tainted data from network controlled interges to the memcpy length argument
import cpp
import semmle.code.cpp.dataflow.TaintTracking
import DataFlow::PathGraph
/**
* An expression involved when swapping the byte order of network data.
* Its value is likely to have been read from the network.
*/
class NetworkByteSwap extends Expr {
NetworkByteSwap() {
exists(MacroInvocation mi |
mi.getMacroName().regexpMatch("ntoh(s|l|ll)") and
this = mi.getExpr()
)
}
}
class Config extends TaintTracking::Configuration {
Config() { this = "no matter" }
override predicate isSource(DataFlow::Node source) {
source.asExpr() instanceof NetworkByteSwap
}
override predicate isSink(DataFlow::Node sink) {
exists(FunctionCall fc | fc.getTarget().getName() = "memcpy" and sink.asExpr() = fc.getArgument(2))
}
}
from Config cfg, DataFlow::PathNode source, DataFlow::PathNode sink
where cfg.hasFlowPath(source, sink)
select sink, source, sink, "Network byte swap flows to memcpy"
CodeQl lab learn的更多相关文章
- RH253读书笔记(1)-Lab 1 System Monitoring
Lab 1 System Monitoring Goal: To build skills to better assess system resources, performance and sec ...
- Learn to securely share files on the blockchain with IPFS!
https://medium.com/@mycoralhealth/learn-to-securely-share-files-on-the-blockchain-with-ipfs-219ee47d ...
- 什么是 Meta Learning / Learning to Learn ?
Learning to Learn Chelsea Finn Jul 18, 2017 A key aspect of intelligence is versatility – the cap ...
- Lab 6-2
Analyze the malware found in the file Lab06-02.exe. Questions and Short Answers What operation does ...
- Lab 6-1
LABS The goal of the labs for this chapter is to help you to understand the overall functionality of ...
- Lab 1-4
Analyze the file Lab01-04.exe. Questions and Short Answers Upload the Lab01-04.exe file to http://ww ...
- Lab 1-1
LABS The purpose of the labs is to give you an opportunity to practice the skills taught in the chap ...
- 第六章:Reminders实验:第二部分[Learn Android Studio 汉化教程]
Learn Android Studio 汉化教程 Reminders Lab: Part 2 This chapter covers capturing user input through the ...
- 第五章:Reminders实验:第一部分[Learn Android Studio 汉化教程]
Learn Android Studio 汉化教程 By now you are familiar with the basics of creating a new project, program ...
- 6.824 Lab 2: Raft 2A
6.824 Lab 2: Raft Part 2A Due: Feb 23 at 11:59pm Part 2B Due: Mar 2 at 11:59pm Part 2C Due: Mar 9 at ...
随机推荐
- Springboot 结合 Netty 实战聊天系统
音视频技术为什么需要微服务 微服务,英文名:microservice,百度百科上将其定义为:SOA 架构的一种变体.微服务(或微服务架构)是一种将应用程序构造为一组低耦合的服务. 微服务有着一些鲜明的 ...
- 使用Net将HTML简历导出为PDF格式
现在有许多将HTML导出PDF的第三方包,这里介绍使用的是Select.HtmlToPdf.NetCore 使用Select.HtmlToPdf.NetCore 整体思路是将cshtml内容读出来,然 ...
- Mybatis Plus根据某字段特定值排序
需求 背景:一个审核流程.审核人等级分为市级和省级,管理员升级字段adminlevel,字段含义:1省级,2市级.审核字段audit为int字段,字段含义:1待市级审核,2待省级审核,3通过审核. 需 ...
- Easy App Locker - 给你的 mac 应用加锁保护你的隐私
Easy App Locker可以对Mac上的单个应用进行密码保护.维护Mac上的隐私. 像如果你的某个应用存在隐私数据就可以使用该软件将此应用上锁,这样当你的朋友使用你的 mac 时你就不用担心你的 ...
- ABC291题解(D-G)
ABC291 D - Flip Cards Solution: 考虑DP,定义状态\(F_{i,0}\)为第\(i\)张卡片正面朝上的方案数,\(F_{i,1}\)为第\(i\)张卡片背面朝上的方案数 ...
- Lombok首字母小写,第二个字母大写,jackson反序列化失败
记一次接口调用字段映射失败问题排查 在写接口的时候遇到一个很神奇的问题,编写一个post接口,在使用包装类接收body的时候发现有个字段映射不上.代码如下 @RestController public ...
- AcWing 1902. 马拉松
题目链接 每次路程改变只对前后两点间距离有影响,因此每次都判断当前三个点之间的距离之和与去掉中间点的距离哪个更优即可,最后取最大值作为结果输出. #include<iostream> #i ...
- [Nginx]安装第三方调试模块——echo | #解决异常#unknown directive “echo”
前言 echo 模块/指令: 在Nginx中是一个第三方开发者----agentzh(章亦春)开发的.功能强大的调试工具. location = /helloworld/ { default_type ...
- [大数据]ETL之增量数据抽取(CDC)
关于:转载/知识产权 本文遵循 GPL开源协议,如若转载: 1 请发邮件至博主,以作申请声明. 2 请于引用文章的显著处注明来源([大数据]ETL之增量数据抽取(CDC) - https://www. ...
- 在smt贴片加工中手工焊接和机器焊接的区别
在smt贴片加工领域,都需要将电子元件贴装在pcb板表面并进行焊接的,常用的焊接方式分为两种:手动焊接和全自动机器焊接,而常用的焊接机器有回流焊机和波峰焊机,那你知道他们的区别是什么吗?安徽英特丽带你 ...