Websockets?

UTCTF Web 문제입니다.

 

Description :

Can you hack my website?

 

본인의 웹사이트를 해킹해 달라는 문제입니다.

 

문제 분석

웹 사이트를 해킹하는 문제인데 제목이 Webscokets 이여서 이 둘의 연관성을 생각하며 진행하겠습니다.

 

index page

최하단에 Employee login 기능을 제외하면 특별한 기능이 없는 page입니다.

해당 페이지의 코드부터 확인하였습니다.

 

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		
		<link rel="stylesheet" href="/static/style.css">
		<title>Fake Corp</title>
		
	</head>
	<body>
		
<div class="content backdrop">

			
<center>
	<h1 class=fancy>Fake Company</h1>
	<span class=fancy>We are dedicated to empowering our customers to 10x their development lifecycle synergies.</span>
	<span class=fancy>Want to learn about our solutions?</span>
	<!-- TODO: this button is set to the wrong URL and for some reason only the 'admin' account can change it. Tom is the only one who knows the passcode and he's out until Wednesday. I'm not paid enough to deal with this so it's just going to be broken for now. It's not like we get traffic anyway 😠 -->
	<a class="fancy button" href="/contact-us">Contact Us</a>
</center>

		</div>
		<div id="footer">
			
			<a href="/internal/login">Employee login</a>
			
		</div>
	</body>
</html>

주석으로 처리된 부분에 'admin' 계정 만이 해당 버튼을 활성화 할수 있습니다라며 admin 계정의 존재 여부에 대해 알려주고 있습니다.

 

employee login

직원 로그인 페이지입니다.

 

<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		
		<link rel="stylesheet" href="/static/style.css">
		<title>Fake Corp</title>
		
	</head>
	<body>
		
		<div class="content">
		
			
<div class="topbox">
	<h1>Login</h1>
	<span class="error"></span>
	<form method="post">
		<input name="username" type="text" placeholder="Username" required> 
		<!-- what is this garbage, you ask? Well, most of our pins are now 16 digits, but we still have some old 3-digit pins left because tom is a moron and can't remember jack -->
		<input name="password" type="password" placeholder="PIN" required pattern="(\d{3}|\d{16})">
		<input type="submit">
	</form>
	<script src="/static/login.js"></script>
</div>

		</div>
		<div id="footer">
			
			<a href="/internal/login">Employee login</a>
			
		</div>
	</body>
</html>

employee login 페이지로 넘어와서 코드를 확인해 보았습니다.

Tom이 멍청해서 아직도 3자리 pin 코드를 사용한다고 알려줍니다.

 

이를 통해 브루트 포스 공격을 이용하여야 된다고 생각하였습니다.

※ 추후 문제를 풀다 알게되었는데 이때 주의할 점은 Username값과 Pin 값이 Webscokets을 통해 통신이 이루어진다는 점이었습니다.

 

 

문제 풀이

employee login

id는 admin으로 설정하고 bruteforce를 진행합니다.

 

from websocket import create_connection

for i in range(900, 1000):
	ws = create_connection("ws://web1.utctf.live:8651/internal/ws")

	print(ws.recv())
	ws.send("begin")
	ws.send("user admin")
	print(i)
	ws.send("pass "+str(i))
	print(ws.recv())

해당과정은 사전에 burp suite를 사용하여 websocket이 어떤내용을 수신하는지 확인하고 제작하였습니다.

 

 

brute force

curl에서 사용하여 접근하거나 획득한 PIN 907을 사용하여 로그인 하면 flag를 획득할 수 있습니다.

 

더보기

utflag{w3bsock3ts}

 

'Challenge > CTF' 카테고리의 다른 글

T3N4CIOUS CTF 2022  (0) 2022.03.26
[dvCTF] ICMP  (0) 2022.03.15
[dvCTF] CyberStreak v1.0  (0) 2022.03.14
[dvCTF] CyberStreak v2.0  (0) 2022.03.14
[dvCTF] RSA  (0) 2022.03.14

CyberStreak v1.0

dvCTF Web 문제입니다.

 

Description :

Thank you for your report !

You can now create your own challenges, delete them, deactivate / activate them.

xXx-michel-xXx

http://challs.dvc.tf:5002

Brute force is strictly forbidden and useless.Hello,

I am a student and I would like to improve my web development skills. To practice, I am creating my first web application. This application is a kind of cybercoach. Example: you want to do sports. A sport goal could be to do 100 push-ups per day for 1 month. The application will allow you to create this "challenge" and each day, you will have to do the number of push-ups you have set and note it in the application. If you don't do the push-ups for 3 days, it's a failure and you lose your streak.

This first version of the application gives you the possibility to create an account and to do the challenge of the example.

Can you test the security of my application ?

xXx-michel-xXx

http://challs.dvc.tf:5001

Brute force is strictly forbidden and useless.

 

푸시업 챌린지가 있습니다. 취약점을 찾아서 신고해주시기 바랍니다.

웹페이지 테스트를 통해 취약점을 찾아내는 문제입니다.

 

 

문제 분석

index page

정보가 없기 때문에 페이지 소스코드,  네트워크 패킷, 쿠키 순으로 살펴보았습니다.

페이지 소스코드는 hidden과 disable 처리된 구문들이 있었지만 문제와는 크게 상관 없었습니다.

네트워크 패킷 또한 눈에 보이는게 없었습니다.

 

cookie

그러던 중 cookie에서 익숙한 형태의 값을 발견하였습니다.

JWT로 추정되며 이를 확인하기 위해 base64로 디코딩 해보았습니다.

 

decoding

JWT인 것이 확실합니다.

 

 

문제 풀이

인코딩하여 제출해보았으나 로그아웃이 이루어질 뿐 flag는 확인할수 없었습니다.

때문에 secret 키가 존재하는지 확인해 보았습니다.

 

username : xXx-michel-xXx
secret : s3cr3t

확인 결과 secret 값이 존재하였으며 username은 해당 서버 소유자인 xXx-michel-xXx로 추정하여 진행하였습니다.

 

encoding

인코딩된 세션값을 획득할 수 있었습니다.

 

flag

해당 값으로 cookie값을 바꿔주게 되면 flag가 나오게 됩니다.

 

더보기

dvCTF{80b8d1A92G6a13a98Dc7b546a7a7Y35}

 

'Challenge > CTF' 카테고리의 다른 글

[dvCTF] ICMP  (0) 2022.03.15
[UTCTF] Websockets?  (0) 2022.03.14
[dvCTF] CyberStreak v2.0  (0) 2022.03.14
[dvCTF] RSA  (0) 2022.03.14
[Codegate2022] PrimeGenerator  (0) 2022.03.07

CyberStreak v2.0

dvCTF Web 문제입니다.

 

Description :

Thank you for your report !

You can now create your own challenges, delete them, deactivate / activate them.

xXx-michel-xXx

http://challs.dvc.tf:5002

Brute force is strictly forbidden and useless.

 

취약점 신고 고맙습니다. 이제 나만의 챌린지를 만들고 삭제 하고 이것저것할수 있습니다.

웹페이지 테스트를 통해 취약점을 찾아내는 문제입니다.

 

문제 분석

New challenge

새로운 페이지에서 취약점을 찾아내야 되는것으로 보입니다.

file upload 기능이 있는것으로 보아 이를 이용하는 LFI 혹은 file_upload를 이용한 웹쉘 취약점인것으로 예상됩니다.

 

request

임의의 값과 파일들을 입력하여 확인을 해보았습니다.

challengename : test

filename : aa

 

url path로 hash값들이 사용되는 것처럼 보여집니다.

 

test hash
aa hash

이를 통해 제가 입력한 값들을 hash화하여 url path로 사용중이라는 사실을 알수 있었습니다.

뿐만 아니라 첫번째 챌린지를 통해 flag의 이미지 파일 이름을 획득할수 있습니다.

 

challengename : xXx-michel-xXx
filename : flaggggggggggggggggggggggg.png

이를 이용하여 url path를 생성합니다.

SHA256(xXx-michel-xXx)/MD5(flaggggggggggggggggggggggg.png2)

 

 

문제 풀이

url path를 생성하여 접근하면 file이 다운로드 됩니다.

7e0c7ec9c02bffca0ff9a9dc26f02f5b
0.01MB

이 파일을 수정해서 flag를 획득할 수 있습니다.

더보기

dvCTF{7rz1nv12kmv35sQaVOfsdzA8fQ}

 

'Challenge > CTF' 카테고리의 다른 글

[UTCTF] Websockets?  (0) 2022.03.14
[dvCTF] CyberStreak v1.0  (0) 2022.03.14
[dvCTF] RSA  (0) 2022.03.14
[Codegate2022] PrimeGenerator  (0) 2022.03.07
[CODEGATE2022] CAFE  (0) 2022.03.05

우리 스파이가 Etulosba CDN의 소스 코드를 훔치는 데 성공했습니다.
해당 서버에서 플래그를 가져오려면 여러분의 도움이 필요합니다.

주어진 main.js 파일 먼저 확인해보도록 하겠습니다.

 

 

main.js 파일입니다.

const fs = require("fs");
const path = require("path");
const express = require("express");

const server = express();

server.get("/", function (req, res) {
    res.end("<html><body>etulosba</body></html>");
});

server.get("/files/images/:name", function (req, res) {
    if (req.params.name.indexOf(".") === -1) {
        return res.status(400).json({ error: "invalid file name" });
    }

    res.sendFile(__dirname + path.join("/files/images/", req.params.name));
});

server.get("/files/binary/:name", function (req, res) {
    if (req.params.name.indexOf(".") !== -1) {
        return res.status(400).json({ error: "invalid file name" });
    }

    res.sendFile(path.resolve(__dirname, "/files/binary/", req.params.name));
});

fs.writeFileSync(path.join(__dirname, "flag.name"), process.env.FLAG_NAME);
fs.writeFileSync(path.join("/tmp", process.env.FLAG_NAME), process.env.FLAG);

server.listen(process.env.HTTP_PORT);

 

특정 주소로부터 flag.name 파일을 가져와야 하고 후에 값을 사용하여 /tmp 안에 있는 플래그 파일을 가져올 수 있습니다.

 

 

think1  이는 LFI를 이용하는 문제로 보입니다. 우선적으로 /files/images/에서 파일을 획득해야됩니다.

약간의 조건이 걸려 있습니다. 

/files/images/:name

위 형식을 유지해야 하며 indexof의 결과 값 즉, 일치하는 결과 값이 없어 -1이 나오게 하면 error을 뿜습니다.

 

 

때문에 아래와 같이 위 형식을 유지하되 index of('.')를 우회 하도록 하여야합니다.

/files/images/%2E%2E%2F%2E%2E%2Fflag%2Ename

그럴 경우 txt 하나를 획득하게 됩니다.

 

 

 

 

think2  이제 폴더명을 획득했으니 위와 유사한 방식으로 /files/binary/에서 파일을 획득해야됩니다.

/tmp 파일 안에 있다고 위에서 언급했으니 다음과 같은 url을 입력해줍니다.

/files/binary%2Ftmp%2Fimaflagimaflag

그 결과 아래와 같이 flag를 획들할수 있었습니다.

 

'Challenge > CTF' 카테고리의 다른 글

[DefCamp CTF 21-22] web-intro  (0) 2022.02.15
[Intent CTF] Graphics  (0) 2021.11.30
[Intent CTF] Careers  (0) 2021.11.22
[Intent CTF] Door (un)Locked  (0) 2021.11.22
[2021 hspace] Baby_Crypto  (0) 2021.05.07

[Intent CTF] Web 카테고리 첫번째 문제입니다.

일부 연구원은 CTF용 웹사이트를 배포하기 시작했지만 플래그를 숨기려고 할 때 정의된 정책에 문제가 발생했습니다.
약한 링크를 찾을 수 있습니까?

think1 정책을 통해서 해당 서버를 보호하고 있으며 정책중에 문제가 있어 취약한 부분을 공격하는 문제인듯 합니다.

 

추가로 제공된 ha.cfg 파일을 확인해보도록 하겠습니다. 내용은 아래와 같습니다.

global
    daemon
defaults  
    mode    http
    timeout  client  50000
    timeout  server  50000
    timeout  connect 50000
frontend web 
    bind *:8000  
    http-request deny if { path_beg /flag }
    http-request deny if { path,url_dec -m reg ^.*/?flag/?.*$ }
    default_backend websrvs
backend websrvs 
    http-reuse always
    server srv1 flask:5000

 

구성과 내용을 기반으로 검색해 보았을 때 ha.cfg 파일은 로드밸런싱 및 보안을 위한 haproxy 파일로 보입니다.

http-request deny로 몇가지 제약사항 필터링이 걸린것을 확인 할수 있습니다.

 

think2 해당 주소 /flag로 접근하기 위해서는 필터링을 무력화해야만 합니다.

필터링 조건들을 한번 살펴 보겠습니다.

http-request deny if { path_beg /flag }

/flag 문자열로 시작되는 요청은 차단된다는 의미입니다.

http-request deny if { path,url_dec -m reg ^.*/?flag/?.*$ }

url을 디코딩한 후에 나오는 값이 정규표현식 ^.*/?flag/?.*$ 문자와 같을 경우 모든 요청을 차단합니다.

이곳에서 자세히 봐야 할것이 있습니다. 정규표현식이 잘못됬다는 것입니다.

표현할때 역슬래쉬로 처리를 해줘야 동작합니다. 

/? -> \/\?

 

think3 /flag가 정확히 어떤주소에 있는지 살펴보겠습니다.

다행히도 url:port 바로 뒤에 /flag가 존재하며 정책에 의해 접근이 불가능 한것을 확인할 수 있습니다.

 

think4 필터링을 우회해보도록 하겠습니다.

/flag로 접속할경우 보안 정책에 의해 403 Forbidden이 Response 값으로 나오게 됩니다.

/flag를 1./flag로 시작하면 안된다. 2. url deocoding한 값이 제시된 정규표현식과 일치해서는 안된다는 조건에 의거하여 /./../flag로 변경하도록 하겠습니다.

 

 

. 때문에 403 Forbidden이 뜨고 있습니다.

정규표현식에서 . 의 경우 line terminators를 이용하여 우회가 가능합니다.

%0a를 사용해보도록 하겠습니다.

 

 

200 정상적으로 Response가 나타나는 것을 확인할수 있습니다.

'Challenge > CTF' 카테고리의 다른 글

[Intent CTF] Etulosba  (0) 2021.11.25
[Intent CTF] Careers  (0) 2021.11.22
[2021 hspace] Baby_Crypto  (0) 2021.05.07
[DiceCTF] web/Web Utils (2)  (0) 2021.03.09
[DiceCTF] web/Web Utils (1)  (0) 2021.02.23

+ Recent posts