Python WSGI 简单实例

2023-11-28

分类: 网络笔记 (评论)

通过python wsgi构建简易http服务器,其中根目录下的static存放demo.html、diy.css作为演示

wsgi.py:

from wsgiref.simple_server import make_server

class Application(object):

    def __init__(self, environ, start_response):
        self.start_response = start_response
        self.path = environ['PATH_INFO']

    def __iter__(self):
        if self.path == '/':
            status = '200 OK'
            response_headers = [('Content-type', 'text/html')]
            self.start_response(status, response_headers)
            yield '<h1>Hello,World!</h1>'.encode('utf-8')
        # /test
        elif self.path == '/test':
            status = '200 OK'
            response_headers = [('Content-type', 'text/html')]
            self.start_response(status, response_headers)
            yield '<h1>test,ok!</h1>'.encode('utf-8')
        # /demo
        elif self.path == '/demo':
            status = '200 OK'
            response_headers = [('Content-type', 'text/html')]
            self.start_response(status, response_headers)
            file = open("static/demo.html")
            res = file.read()
            # print(res)
            yield res.encode('utf-8')
        # *.css
        elif self.path.endswith(".css"):
            status = '200 OK'
            response_headers = [('Content-Type', 'text/css; charset=utf-8')]
            self.start_response(status, response_headers)
            print('read css file', "static" + self.path)
            file = open("static" + self.path)
            res = file.read()
            yield res.encode('utf-8')
        # 404
        else:
            status = '404 NOT FOUND'
            response_headers = [('Content-type', 'text/html')]
            self.start_response(status, response_headers)
            yield '<h1>404 NOT FOUND</h1>'.encode('utf-8')


if __name__ == "__main__":
    app = make_server('127.0.0.1', 8000, Application)
    print('Serving HTTP start ...')
    app.serve_forever()

static目录下的demo.html:

<html>
<head>
    <title>Demo</title>
    <link rel="stylesheet" type="text/css" href="diy.css">
</head>
<body>
demo body
<div class="label">bbb</div>
</body>
</html>

static目录下的diy.css:

.label {
  color: red;
  font-size: 30px;
}

通过HashCat破解office密码

2023-09-11

分类: 网络笔记 (评论)

hashcat 是一款免费的密码破解工具。它支持使用 AMD 和 NVidia 显卡运算,同时也保留使用 cpu 计算的版本。hashcat 号称是世界上最快的密码破解工具,同时也是世界上第一款和唯一一款使用通用图形处理器的工具。它支持 windows 和 linux 操作系统,同时支持 OpenCL 和 CUDA。hashcat 可以支持破解包括 MD5,sha1 等 150 多种加密算法生成的密码。

使用 hashcat 破解 office 密码的时候需要指定加密方式,Office 03 - 2013 一共有 9 种 hash 方式,分别如下:

Office 97-03(MD5+RC4,oldoffice$0,oldoffice$1): flag -m 9700
Office 97-03(MD5+RC4,collider-mode#1): flag -m 9710
Office 97-03(MD5+RC4,collider-mode#2): flag -m 9720
Office 97-03(SHA1+RC4,oldoffice$3,oldoffice$4): flag -m 9800
Office 97-03(SHA1+RC4,collider-mode#1): flag -m 9810
Office 97-03(SHA1+RC4,collider-mode#2): flag -m 9820
Office 2007: flag -m 9400
Office 2010: flag -m 9500
Office 2013: flag -m 9600

破解步骤

获取文件 hash 值

首先,我们需要获取文件的 hash 值,使用office2john.py可以提取文件的 hash 值。

在命令行中执行:

python office2john.py test.xls

得到的 hash 结果为:

test.xls:$oldoffice$0*2031e09b28a2a13a891dff99bae0927d*65264ab10fdde25b22146e2c94778c50*981ec9419aa5dd88c0340491ed07f38c:::936 111 730895 936 11112798626794 12798538993 12932656957 Microsoft Excel 1::test.xls

第一个:号前边是文件名,紧跟着的是加密方式,这里是oldoffice$0。然后在 hashcat 官网的
wiki页面的 options 中Generic hash types 找到对应的代号,这里oldoffice$0的代号是 9700。我们用 hashcat 只需要第一个冒号和第二个冒号之间的内容。

因此得到hash为:

$oldoffice$0*2031e09b28a2a13a891dff99bae0927d*65264ab10fdde25b22146e2c94778c50*981ec9419aa5dd88c0340491ed07f38c

将得到的 hash 值保存到文本文件中,这里保存到 hash.txt 里。

使用 hashcat GPU破解:
hashcat 可以使用字典或者掩码对密码进行攻击。一开始我使用掩码,但是使用较短位数密码时它不断警告字典空间过小,无法发挥 GPU 的并行运算能力。所以我这里使用了字典。
因为这个文件是我同学交给我让我帮忙找回密码的,我猜测密码可能是纯数字的,并且有可能在 8 位以下。我首先生成了一个 4 到 8 位数字密码的字典。

在 hashacat 目录下打开命令行,输入下面的命令开始破解:

cudaHashcat64.exe -a 0 -m 9700 -o found.txt hash.txt F:wordlistwordlist
  • cudaHashcat64.exe 是在英伟达显卡电脑上要运行的版本。
  • -a 参数指定攻击方式,这里的 0 表示使用字典攻击,1代表组合攻击,3代表掩码攻击。
  • -m 参数指定密码加密方式,这里使用我们查到的 9700,代表我们的 excel2003 加密。
  • -o 指定结果输出的位置,这里指定输出到 found.txt。接下来 hash.txt 是保存 hash 值的文件名,F:wordlistwordlist是字典的位置和文件名。
如果使用 hashcat CPU破解,命令如下:
hashcat.exe -a 3 -m 9700 -o found.txt hash.txt

在经过系统自动计算后,文件的密码被算出。屏幕上输出状态,程序结束运行。结果将输出到 found.txt 中。

群晖DownloadStation中的BT搜索插件无法删除解决办法

2023-06-20

分类: 网络笔记 (评论)

如果在DownloadStation无法删除某个插件,则需要开启群晖的SSH功能,并通过SSH链接工具到群晖的LINUX系统中
在以下文件夹中找到对应插件

cd /volume1/@appconf/DownloadStation/download/userplugins/
ls

用ls命令列举用户插件目录中所有插件子目录,然后执行对应的插件子目录删除命令(例如xxx是插件目录)即可:rm -rf ./xxxx

windows下一键生成当前磁盘所有文件结构目录树脚本

2023-04-28

分类: 网络笔记 (评论)

有时候需要对某个文件下的所有文件进行一个汇总统计,那么借助于windows 的tree命令可以实现这一想法。

枚举当前文件夹下的所有文件和目录结构并生成树型结构.txt。

- 阅读剩余部分 -

windows下一键生成当前文件夹文件结构目录树脚本

2023-04-21

分类: 网络笔记 (评论)

有时候需要对某个文件下的所有文件进行一个汇总统计,那么借助于windows 的tree命令可以实现这一想法。

枚举当前文件夹下的所有文件和目录结构并生成树型结构.txt。

- 阅读剩余部分 -