DC-9

admin 2024年1月12日13:17:24评论9 views字数 5881阅读19分36秒阅读模式

前言

首先大家一定要记住,所有未经授权的渗透都是违法的,所以大家切勿一通乱黑,被关进橘子有的哭了。我们可以在本地搭建一些本地靶场,比如Dvwa

项目介绍  

靶机:172.16.10.39

攻击机:172.16.10.13;172.16.10.33

一、信息收集  

1.主机信息  

DC-9

2.端口信息  

DC-9    

3.服务信息  

DC-9

二、漏洞分析  

1.Web信息  

访问80看到是一个员工信息的模板首页。

DC-9

上面说让我们随便选择一个菜单选项,在Display All Records中能够看到一些用户信息,    

DC-9

2.漏洞扫描  

在shearch.php页面上手工测试,看不到报错,这是因为没有回显,使用工具进行扫描发现存在一个sql注入漏洞

DC-9

根据请求的url直接进行脱库,这里使用sqlmap    

DC-9

这里可以看到有三个数据库,其中information_schema是默认的库

3.枚举Staff库中的表  

DC-9

4.枚举表Users中的字段  

DC-9

5.枚举users表中的内容  

DC-9

拿到的密码并不是个明文密码,进行md5解密

+DC-9    

得到明文:transorbital1,在看看Users库中的信息    

DC-9

看到这个跟员工信息刚好对的上,随便用一个用户去登入Web看看,结果不行。接着前面的admin用户试一下,发现成功登入

DC-9

登入后发现一个喜欢看到的玩意,看到这样的可以猜测存在文件包含漏洞,这里我们不知道传参,下面我们进行遍历一下使用    

DC-9

6.漏洞利用  

现在就可以利用文件包含漏洞去读取了

DC-9    

看到这里面的账号跟Users库中的账号完全匹配,猜测可能是系统的账号密码,前面我们扫描端口时发现22端口被防火墙过滤了,下面我们看看ssh的配置文件

DC-9

看的不是很直观,可以筛选也可以按ssh的配置文件格式格式化一下,如下所示

# $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj Exp $ # This is the sshd server system-wide configuration file. See # sshd_config(5) for more information. # This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin # The strategy used for options in the default sshd_config shipped with # OpenSSH is to specify options with their default value where # possible, but leave them commented. Uncommented options override the # default value. #Port 22 #AddressFamily any #ListenAddress 0.0.0.0 #ListenAddress :: #HostKey /etc/ssh/ssh_host_rsa_key #HostKey /etc/ssh/ssh_host_ecdsa_key #HostKey /etc/ssh/ssh_host_ed25519_key # Ciphers and keying #RekeyLimit default none # Logging     #SyslogFacility AUTH #LogLevel INFO # Authentication: #LoginGraceTime 2m #PermitRootLogin prohibit-password #StrictModes yes #MaxAuthTries 6 #MaxSessions 10 #PubkeyAuthentication yes # Expect .ssh/authorized_keys2 to be disregarded by default in future. #AuthorizedKeysFile .ssh/authorized_keys .ssh/authorized_keys2 #AuthorizedPrincipalsFile none #AuthorizedKeysCommand none #AuthorizedKeysCommandUser nobody # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts #HostbasedAuthentication no # Change to yes if you don't trust ~/.ssh/known_hosts for # HostbasedAuthentication #IgnoreUserKnownHosts no # Don't read the user's ~/.rhosts and ~/.shosts files #IgnoreRhosts yes # To disable tunneled clear text passwords, change to no here! #PasswordAuthentication yes #PermitEmptyPasswords no # Change to yes to enable challenge-response passwords (beware issues with # some PAM modules and threads) ChallengeResponseAuthentication no # Kerberos options #KerberosAuthentication no #KerberosOrLocalPasswd yes #KerberosTicketCleanup yes #KerberosGetAFSToken no # GSSAPI options #GSSAPIAuthentication no #GSSAPICleanupCredentials yes #GSSAPIStrictAcceptorCheck yes #GSSAPIKeyExchange no # Set this to 'yes' to enable PAM authentication, account processing, # and session processing. If this is enabled, PAM authentication will # be allowed through the ChallengeResponseAuthentication and # PasswordAuthentication. Depending on your PAM configuration, # PAM authentication via ChallengeResponseAuthentication may bypass # the setting of "PermitRootLogin without-password". # If you just want the PAM account and session checks to run without # PAM authentication, then enable this but set PasswordAuthentication     # and ChallengeResponseAuthentication to 'no'. UsePAM yes #AllowAgentForwarding yes #AllowTcpForwarding yes #GatewayPorts no X11Forwarding yes #X11DisplayOffset 10 #X11UseLocalhost yes #PermitTTY yes PrintMotd no #PrintLastLog yes #TCPKeepAlive yes #PermitUserEnvironment no #Compression delayed #ClientAliveInterval 0 #ClientAliveCountMax 3 #UseDNS no #PidFile /var/run/sshd.pid #MaxStartups 10:30:100 #PermitTunnel no #ChrootDirectory none #VersionAddendum none # no default banner path #Banner none # Allow client to pass locale environment variables AcceptEnv LANG LC_* # override default of no subsystems Subsystem sftp /usr/lib/openssh/sftp-server # Example of overriding settings on a per-user basis #Match User anoncvs # X11Forwarding no # AllowTcpForwarding no # PermitTTY no # ForceCommand cvs server

从配置文件中可知,ssh中并没有做什么限制,看看系统运行着什么防火墙,没有远程命令执行漏洞的情况下如何知道所运行的服务呢,这里推荐一个看正在运行的进程查看,是最可靠的,如下所示:    

DC-9

通过搜索iptables、firewalld-cmd、uwf都没有匹配的结果,这样看可能很不直观,下面我把这些内容拷贝一下复制到我们的攻击机上新建一个dajun.txt文件粘贴进去,使用下面命令过滤一下

# cat dajun.txt | egrep '[a-zA-Z]+' -o |sort|uniq               addrconfagettyamdapacheataavgbalancebashbhbwcfschildclkclockcontribconvercost    countcpucpuhpcroncryptocurrdaemondbusDebugdevfreqdhclientdledacehenqueuedestexecfeaturesfirstgpgranularityHIidleIextimklogimuxsockinipvirqjbdjiffiesjournalkauditdkblockdkcompactdkdevtmpfskeykhugepagedkhungtaskdkintegritydknockdksmdksoftirqd    kstrpkswapdkthreaddkthrotldktimekworkerlatencyloadlogaritmiclogindmainmaxMHzmigrationmigratoryminMINmmmysqldnetnsnextnroomoverpamparpciehppercpupidPIDpollerprioQRrcureaperRegremovedresolverqrsrsvrsyslogdrt    runnablerunningrunsruntimeSscalingschedSchedscsisdsdasffsleepspreadsshdSsystemdstablesusumswapswitchessysctlsystemdtasktaskstgthrottlethrottledtimetimesyntmftotaltreettmtunableuudevduninterruptibleupdatesutilvVersionvmwgfxvruntime    waitwakeupwatchdogdweightwqwriteback

虽然在进程中没有看到防火墙的进程,但我们找到一个过滤包的东西,如果不玩运维或者云服务器的可能就回忽略knockd这个服务。感兴趣的可以了解一下,在knockd的配置文件中保留着端口触发暗号,默认配置文件在/etc/knockd_conf中

DC-9

这是一个 knockd 配置内容,其中定义了两个操作:一个是打开 SSH 端口,另一个是关闭 SSH 端口。敲门的顺序和超时时间以及执行的命令都已经配置。

下面看一下没敲门前ssh的端口状态

DC-9

这里可以使用telnet,nc,nmap等敲门触发syn连接    

DC-9

现在就已经成功打开了ssh端口,下面我们使用Users库中拿到的用户和密码进行测试,找到可以登入系统的账号

DC-9

成功找到3个可以登入的系统账号

三、权限提升  

1.提权  

登入三个账号,权限信息。在三个账号中发现都没有可以提权的东西,但在janitor的家目录看到一个隐藏目录/home/janitor/.secrets-for-putin,在目录中存在一个密码文件,名为passwords-found-on-post-it-notes.txt的文件,内容如下所示:    

DC-9

这里的密码肯定是有用,目前还不知道是那个用户的密码,下面我们进行猜解密码。先将上面的密码写入文件中,pass.txt

DC-9

成功猜解出用户和密码

User:fredf

Pass: B4-Tru3-001

登入fredf用户

DC-9

2.查看suid权限的软件  

Find没有找到可以利用的suid权限的软件或程序

DC-9    

3.查看sudo权限  

发现可以以root用户并且不需要密码去执行/opt/devstuff/dist/test/test这个程序

DC-9

看到这个dist目录有点像python编译后的可执行文件目录,比如exe、LFE的可执行程序在python中默认转化后的路径保存位置,进入目录验证一下猜测

DC-9

看到test,py和__pycache__已经可以确定了,这里的test.py就是源文件。我们查看一下源文件内容写的是什么

DC-9

这是一个简单的python脚本,它接受两个参数,分别用于读取文件和将读取的内容追加到另一个文件中。如果命令行参数的数量不是 3,脚本将打印用法说明并退出。否则,它将打开第一个文件进行读取,然后将内容追加到第二个文件中。    

5.利用sudo提权  

利用sudoers配置文件进行提权,创建一个dajun.txt文件,添加内容“fredfALL=(ALL:ALL) ALL”,添加完后在执行test程序读取dajun.txt文件,并追加到sudoers文件中

DC-9

DC-9

没有报错说明已经成功写入到了/etc/sudoers中,可以验证一下

DC-9

看看我们追加到/etc/sudoers下的内容

DC-9

这里有两行是因为执行在敲命令的时候敲了两次

成功提权到root

6.利用user提权  

1)方法1  

创建一个dajun.txt文件并向文件写入如下内容    

DC-9

使用/opt/devstuff/dist/test/test将dajun.txt文件中的内容追加到/etc/passwd中

2)方法2  

DC-9

写入成功,进入dajun用户,进入成功后发现成功登入

DC-9    

7.查看flag  

DC-9

四、权限维持  

五、痕迹清理  

   

原文始发于微信公众号(Red Teams):DC-9

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2024年1月12日13:17:24
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   DC-9http://cn-sec.com/archives/2384513.html

发表评论

匿名网友 填写信息