0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【TryHackMe】Introduction to Django:Walkthrough

Last updated at Posted at 2024-12-19

概要

TryHackMe「Introduction to Django」のWalkthroughです。

Task2

Q1.How would we create an app called Forms?

A.python3 manage.py startapp Forms

Q2.How would we run our project to a local network?

A.python3 manage.py runserver 0.0.0.0:8000

Task4

Q1.Flag from GitHub page

下記リポジトリにアクセスします。

READMEにフラグがあります。

image.png

A.THM{g1t_djang0_hUb}

Task5

Q1.Admin panel flag?

ポートスキャンを実行します。

$ nmap -Pn -T4 -sVC -A -p- 10.10.115.76 -oN nmap_result
PORT     STATE SERVICE  VERSION
22/tcp   open  ssh      OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey: 
|   2048 35:30:91:45:b9:d1:ed:5a:13:42:3e:20:95:6d:c7:b7 (RSA)
|   256 f5:69:6a:7b:c8:ac:89:b5:38:93:50:2f:05:24:22:70 (ECDSA)
|_  256 8f:4d:37:ba:40:12:05:fa:f0:e6:d6:82:fb:65:52:e8 (ED25519)
8000/tcp open  http-alt WSGIServer/0.2 CPython/3.6.9
|_http-title: DisallowedHost          at /
|_http-server-header: WSGIServer/0.2 CPython/3.6.9
| fingerprint-strings: 
|   FourOhFourRequest: 
|     HTTP/1.1 400 Bad Request
|     Date: Thu, 19 Dec 2024 14:35:54 GMT
|     Server: WSGIServer/0.2 CPython/3.6.9
|     Content-Type: text/html
|     Connection: close
|     <!DOCTYPE html>
|     <html lang="en">
|     <head>
|     <meta http-equiv="content-type" content="text/html; charset=utf-8">
|     <meta name="robots" content="NONE,NOARCHIVE">
|     <title>DisallowedHost
|     /nice ports,/Trinity.txt.bak</title>
|     <style type="text/css">
|     html * { padding:0; margin:0; }
|     body * { padding:10px 20px; }
|     body * * { padding:0; }
|     body { font:small sans-serif; background-color:#fff; color:#000; }
|     body>div { border-bottom:1px solid #ddd; }
|     font-weight:normal; }
|     margin-bottom:.8em; }
|     margin:1em 0 .5em 0; }
|     margin:0 0 .5em 0; font-weight: normal; }
|     code, pre { font-size: 100%; white-space: pre-wrap; }
|     table { border:1px solid #ccc; border-collapse: collapse; width:100%; ba
|   GetRequest: 
|     HTTP/1.1 400 Bad Request
|     Date: Thu, 19 Dec 2024 14:35:48 GMT
|     Server: WSGIServer/0.2 CPython/3.6.9
|     Content-Type: text/html
|     Connection: close
|     <!DOCTYPE html>
|     <html lang="en">
|     <head>
|     <meta http-equiv="content-type" content="text/html; charset=utf-8">
|     <meta name="robots" content="NONE,NOARCHIVE">
|     <title>DisallowedHost
|     /</title>
|     <style type="text/css">
|     html * { padding:0; margin:0; }
|     body * { padding:10px 20px; }
|     body * * { padding:0; }
|     body { font:small sans-serif; background-color:#fff; color:#000; }
|     body>div { border-bottom:1px solid #ddd; }
|     font-weight:normal; }
|     margin-bottom:.8em; }
|     margin:1em 0 .5em 0; }
|     margin:0 0 .5em 0; font-weight: normal; }
|     code, pre { font-size: 100%; white-space: pre-wrap; }
|     table { border:1px solid #ccc; border-collapse: collapse; width:100%; background:white; }
|_    tbody

ポートの稼働状況が分かりました。

ポート サービス バージョン
22 ssh OpenSSH 7.6p1
8000 http WSGIServer/0.2 CPython/3.6.9

8000番ポートにアクセスするとエラーが出ています。
ALLOWED_HOSTSにIPアドレスを追加する必要がありそうです。

image.png

ユーザー名とパスワードが既に与えられているのでSSHログインが出来ました。

$ ssh django-admin@10.10.115.76
django-admin@py:~$

messageboxディレクトリを発見しました。

$ ls -la
total 60

(省略)

drwxr-xr-x  4 django-admin django-admin 4096 Apr 10  2020 messagebox

中にはDjangoアプリのデータがあります。

$ ls -la
total 160
drwxr-xr-x 4 django-admin django-admin   4096 Apr 10  2020 .
drwxr-xr-x 9 django-admin django-admin   4096 Dec 19 14:12 ..
-rw-r--r-- 1 django-admin django-admin 135168 Apr 10  2020 db.sqlite3
-rw-r--r-- 1 django-admin django-admin   6148 Apr 10  2020 .DS_Store
drwxr-xr-x 5 django-admin django-admin   4096 Apr 10  2020 lmessages
-rwxr-xr-x 1 django-admin django-admin    630 Apr 10  2020 manage.py
drwxr-xr-x 3 django-admin django-admin   4096 Apr 10  2020 messagebox

messagebox/settings.pyALLOWED_HOSTSにIPアドレスを追加します。

messagebox/settings.py
ALLOWED_HOSTS = ['0.0.0.0', '127.0.0.1', '10.10.115.76']

8000番ポートにアクセス出来ました。

image.png

/adminが管理パネルなので与えられている認証情報でログインを試みると失敗しました。

image.png

Djangoのスーパーユーザーを作成します。

$ python3 manage.py createsuperuser
Username (leave blank to use 'django-admin'): admin
Email address: admin@admin.com
Password: 
Password (again): 
The password is too similar to the username.
This password is too short. It must contain at least 8 characters.                                     
This password is too common.                                                                           
Bypass password validation and create user anyway? [y/N]: y                                            
Superuser created successfully.

作成したアカウントでログインに成功しました。

image.png

Usersからフラグを得られました。

image.png

A.THM{DjanGO_Adm1n}

Q2.User flag?

続いてUsersを見ていくとSSH用のアカウントもあるようです。

image.png

指定されたpastebinのURLにアクセスするとハッシュ値があります。

image.png

ハッシュ値を解析し、平文を特定できました。

image.png

StrangeFoxアカウントでSSH接続に成功しました。

$ ssh StrangeFox@10.10.115.76
StrangeFox@py:~$

/home/StrageFox/user.txtからユーザーフラグを入手できました。

/home/StrageFox/user.txt
THM{SSH_gUy_101}

A.THM{SSH_gUy_101}

Q3.Hidden flag?

Hint.Did you see any identical files?

/home/django-admin/messagebox/messagebox/home.htmlにフラグを発見しました。

/home/django-admin/messagebox/messagebox/home.html
{% extends 'base.html' %}
{% block title %}Home page{% endblock %}

{% block content %}
        <body bgcolor="#E6E6FA">
        <h1><center>Message box v1.1</center></h1>
        <br>
        <center><p>Hi! Welcome back to your inbox. Seems like you got a new message!</p></center>
        <center><p>Check it out here:</p></center>
        <center><p><a href="/messages">Messages</a></p></center>
        <!-- Flag 3: THM{django_w1zzard} -->

{% endblock %}

A.THM{django_w1zzard}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?