Java
  • About This Book
  • 🍖Prerequisites
    • 反射
      • 反射基本使用
      • 高版本JDK反射绕过
      • 反射调用命令执行
      • 反射构造HashMap
      • 方法句柄
    • 类加载
      • 动态加载字节码
      • 双亲委派模型
      • BCEL
      • SPI
    • RMI & JNDI
      • RPC Intro
      • RMI
      • JEP 290
      • JNDI
    • Misc
      • Unsafe
      • 代理模式
      • JMX
      • JDWP
      • JPDA
      • JVMTI
      • JNA
      • Java Security Manager
  • 👻Serial Journey
    • URLDNS
    • SerialVersionUID
    • Commons Collection 🥏
      • CC1-TransformedMap
      • CC1-LazyMap
      • CC6
      • CC3
      • CC2
    • FastJson 🪁
      • FastJson-Basic Usage
      • FastJson-TemplatesImpl
      • FastJson-JdbcRowSetImpl
      • FastJson-BasicDataSource
      • FastJson-ByPass
      • FastJson与原生反序列化(一)
      • FastJson与原生反序列化(二)
      • Jackson的原生反序列化利用
    • Other Components
      • SnakeYaml
      • C3P0
      • AspectJWeaver
      • Rome
      • Spring
      • Hessian
      • Hessian_Only_JDK
      • Kryo
      • Dubbo
  • 🌵RASP
    • JavaAgent
    • JVM
    • ByteCode
    • JNI
    • ASM 🪡
      • ASM Intro
      • Class Generation
      • Class Transformation
    • Rasp防御命令执行
    • OpenRASP
  • 🐎Memory Shell
    • Tomcat-Architecture
    • Servlet API
      • Listener
      • Filter
      • Servlet
    • Tomcat-Middlewares
      • Tomcat-Valve
      • Tomcat-Executor
      • Tomcat-Upgrade
    • Agent MemShell
    • WebSocket
    • 内存马查杀
    • IDEA本地调试Tomcat
  • ✂️JDBC Attack
    • MySQL JDBC Attack
    • H2 JDBC Attack
  • 🎨Templates
    • FreeMarker
    • Thymeleaf
    • Enjoy
  • 🎏MessageQueue
    • ActiveMQ CNVD-2023-69477
    • AMQP CVE-2023-34050
    • Spring-Kafka CVE-2023-34040
    • RocketMQ CVE-2023-33246
  • 🛡️Shiro
    • Shiro Intro
    • Request URI ByPass
    • Context Path ByPass
    • Remember Me反序列化 CC-Shiro
    • CB1与无CC依赖的反序列化链
  • 🍺Others
    • Deserialization Twice
    • A New Blazer 4 getter RCE
    • Apache Commons Jxpath
    • El Attack
    • Spel Attack
    • C3P0原生反序列化的JNDI打法
    • Log4j
    • Echo Tech
      • SpringBoot Under Tomcat
    • CTF 🚩
      • 长城杯-b4bycoffee (ROME反序列化)
      • MTCTF2022(CB+Shiro绕过)
      • CISCN 2023 西南赛区半决赛 (Hessian原生JDK+Kryo反序列化)
      • CISCN 2023 初赛 (高版本Commons Collections下其他依赖的利用)
      • CISCN 2021 总决赛 ezj4va (AspectJWeaver写字节码文件到classpath)
      • D^3CTF2023 (新的getter+高版本JNDI不出网+Hessian异常toString)
      • WMCTF2023(CC链花式玩法+盲读文件)
      • 第六届安洵杯网络安全挑战赛(CB PriorityQueue替代+Postgresql JDBC Attack+FreeMarker)
  • 🔍Code Inspector
    • CodeQL 🧶
      • Tutorial
        • Intro
        • Module
        • Predicate
        • Query
        • Type
      • CodeQL 4 Java
        • Basics
        • DFA
        • Example
    • SootUp ✨
      • Intro
      • Jimple
      • DFA
      • CG
    • Tabby 🔦
      • install
    • Theory
      • Static Analysis
        • Intro
        • IR & CFG
        • DFA
        • DFA-Foundation
        • Interprocedural Analysis
        • Pointer Analysis
        • Pointer Analysis Foundation
        • PTA-Context Sensitivity
        • Taint Anlysis
        • Datalog
Powered by GitBook
On this page
  • Primitive types
  • Classes
  • definition
  • class bodies
  • inheritance
  • concrete class
  • abstract class

Was this helpful?

  1. 🔍Code Inspector
  2. CodeQL 🧶
  3. Tutorial

Type

QL是静态类型语言(statically typed),即每个变量必须声明类型

类型是值的集合,一个值可能属于一个或多个集合,即一个值可能有多种类型

Primitive types

原始的内置类型,boolean、float、int、string、date

QL提供了一系列内置的定义在原始类型的操作

Classes

类代表单一的值集。QL中的类并不会创建一个新对象,它只是将满足某种逻辑属性的值归为一组。

definition

自定义类:

  • 关键字class

  • 类名(大写字母开头)

  • 超类的继承或实现(extends、instanceof)

  • 类的主体(包括characteristic predicate、member predicate、fields)

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
  }
}

class bodies

定义一个类后,它会从父类继承非私有的成员谓词和字段

  • Characteristic predicates

特征谓词,类似构造函数,使用this变量限制了当前类所表示的数据集合(represent logic properties)

如上例子中将int集合又进一步限制在了1、2、3

  • Member predicates

成员谓词,包含特定于该类值集的操作,只能应用于某一class的成员的谓词(class的成员member需要是characteristic predicate中声明的)

如1.(OneTwoThree).getAString()返回"One, two or three: 1"

(OneTwoThree)用于强转(cast),保证1有OneTwoThree这个type而不只是int

  • Fields

类里面定义的变量,可以在类的谓词定义中使用这些变量,类似变量this,fields必须在characteristic predicate做出限制。

class SmallInt extends int {
  SmallInt() { this = [1 .. 10] }
}

class DivisibleInt extends SmallInt {
  SmallInt divisor;   // declaration of the field `divisor`
  DivisibleInt() { this % divisor = 0 }

  SmallInt getADivisor() { result = divisor }
}

from DivisibleInt i
select i, i.getADivisor()

QL中的class必须至少有一个supertype

inheritance

  • extension

如果一个class继承了supertype,可以重写继承到的member predicate

class OneTwo extends OneTwoThree {
  OneTwo() {
    this = 1 or this = 2
  }

  override string getAString() {
    result = "One or two: " + this.toString()
  }
}
from OneTwoThree o
select o, o.getAString()

和其他面向对象语言不同,上面的查询语句会首先遍历子类的值域,对其应用getAString,再对父类和子类值域的差集应用getAString

o

getAString() result

1

One or two: 1

2

One or two: 2

3

One, two or three: 3

若我们再定义一个子类,若子类值域相交,相交部分会被多次调用

class TwoThree extends OneTwoThree {
  TwoThree() {
    this = 2 or this = 3
  }

  override string getAString() {
    result = "Two or three: " + this.toString()
  }
}

o

getAString() result

1

One or two: 1

2

One or two: 2

2

Two or three: 2

3

Two or three: 3

一个类可以继承多种类型,其值取父类的交集

如果父类有相同的方法,该类必须重写该方法

  • final extension

一个类可以继承final类型,该类会继承父类最终版本的成员谓词和字段,并且通过final extension继承到的成员谓词不能重写,但可以被隐藏(shadowed)

final class FinalOneTwoThree = OneTwoThree;

class OneTwoFinalExtension extends FinalOneTwoThree {
  OneTwoFinalExtension() {
    this = 1 or this = 2
  }

  string getAString() {
    result = "One or two: " + this.toString()
  }
}

from OneTwoThree o
select o, o.getAString()
1
1
One, two or three: 1

2

2

One, two or three: 2

3

3

One, two or three: 3

和重写不同,final extension保持继承类不变,看到这里并不会调用OneTwoFinalExtension#getAString

  • instanceof

除了extend base types,class还能声明instanceof建立和其他types的关系

class Foo extends int {
  Foo() { this in [1 .. 10] }

  string fooMethod() { result = "foo" }
}

class Bar instanceof Foo {
  string toString() { result = super.fooMethod() }
}

上面实例可以看成在类Bar的特征谓词中声明this instanceof Foo

Foo的特征谓词能作用到Bar,但成员谓词不能被Bar直接调用,得通过super关键字

select any(Bar b).fooMethod()编译会报错

此外instanceof supertypes并不能重写父类的成员谓词

concrete class

上面定义的都是具体类,通过在更大范围的父类基础上进行值的限制,即父类跟characteristic predicate的交集

(A restriction of the values in a larger type)

abstract class

由abstract修饰的类为抽象类,抽象类是其子类的并集(union)

一个抽象类的值必须满足其本身和其子类的characteristic predicate

有点OOP多态的赶脚

abstract class SqlExpr extends Expr {
  ...
}
PreviousQueryNextCodeQL 4 Java

Last updated 11 months ago

Was this helpful?