# 取证

<p align="center">
    <img src="../../../assets/img/Security/BlueTeam/取证/3.png">
</p>

> 注 : 笔记中拓扑图 xmind 源文件在其图片目录下

---

## 免责声明

`本文档仅供学习和研究使用,请勿使用文中的技术源码用于非法用途,任何人造成的任何负面影响,与本人无关.`

---

# 大纲

* **[操作系统取证](#操作系统取证)**
    * [Android](#android)
    * [Windows](#windows)
    * [Linux](#linux)

* **[文件取证](#文件取证)**
    * [压缩包](#压缩包)
        * [爆破压缩包](#爆破压缩包)
        * [伪加密](#伪加密)
        * [明文攻击](#明文攻击)
        * [CRC32碰撞](#crc32碰撞)
    * [视频](#视频)
        * [Deegger_Embedder](#deegger_embedder)
    * [图片](#图片)
        * [LSB隐写](#lsb隐写)
        * [exif](#exif)
    * [音频](#音频)
    * [电子文档](#电子文档)
        * [Office](#Office)
            * [爆破Office加密](#爆破Office加密)
        * [PDF](#pdf)
            * [爆破PDF加密](#爆破PDF加密)

* **[流量分析](#流量分析)**

* **[USB取证](#USB取证)**

* **[蓝牙取证](#蓝牙取证)**

* **[磁盘取证](#磁盘取证)**

* **[内存取证](#内存取证)**

* **[应用程序取证](#应用程序取证)**
    * [远程连接工具取证](#远程连接工具取证)
    * [浏览器取证](#浏览器取证)

* **[WEB取证](#WEB取证)**
    * [中间件配置](#中间件配置)
    * [中间件服务器程序日志](#中间件服务器程序日志)

* **[数据库取证](#数据库取证)**
    * [mysql](#mysql)
    * [mssql](#mssql)
    * [Oracle](#oracle)

---

# 操作系统取证

## Android

![](../../../assets/img/Security/BlueTeam/取证/手机取证.jpg)

## Windows

- [Windows加固+维护+应急响应参考](../../Integrated/Windows/Secure-Win.md)

**通用取证工具**
- [The Sleuth Kit (TSK)](https://www.sleuthkit.org/) - 一套强大的数字调查、取证工具集合

**系统日志**

- 内容见 [Secure-Win](../../Integrated/Windows/Secure-Win.md#日志) 日志部分

**DNS**

- 内容见 [Secure-Win](../../Integrated/Windows/Secure-Win.md#dns) DNS 部分

**动作记录**
- 工具
    - [Device Cleanup Tool](https://www.uwe-sieber.de/misc_tools_e.html) - 查看电脑连接过的设备
    - [LastActivityView](https://www.nirsoft.net/utils/computer_activity_view.html) - 最近你干什么了
    - [OpenSaveFilesView](https://www.nirsoft.net/utils/open_save_files_view.html) - 显示文件打开、保存记录
    - [TurnedOnTimesView](https://www.nirsoft.net/utils/computer_turned_on_times.html) - 快速查看系统开关机时间
    - [uknowsec/loginlog_windows](https://github.com/uknowsec/loginlog_windows) - 读取登录过本机的登录失败或登录成功的所有计算机信息

**key**
- 本部分见 [Windows 安全](../RedTeam/OS安全/Windows安全.md#认证)

**蓝牙**
- 工具
    - [bluetoothview](https://www.nirsoft.net/utils/bluetooth_viewer.html) - 监控周围的蓝牙设备

**无线**
- 工具
    - [wifihistoryview](https://www.nirsoft.net/utils/wifi_history_view.html) - Wi-Fi 连接历史记录
    - [wirelesskeyview](https://www.nirsoft.net/utils/wireless_key.html)- 查看本地 wifi 密码

**NTFS 记录**

- 相关工具
    - [jschicht/UsnJrnl2Csv](https://github.com/jschicht/UsnJrnl2Csv)

## Linux

- [日志](../../Integrated/Linux/笔记/日志.md)
- [Linux基本信息查询命令](../../Integrated/Linux/笔记/信息.md)
- [Linux加固+维护+应急响应参考](../../Integrated/Linux/Secure-Linux.md)

---

# 文件取证

**文件取证常用工具**
- [binwalk](https://github.com/ReFirmLabs/binwalk) - 固件分析工具
    - kali 自带, 递归提取 `binwalk -Me xxx.bin`
- foremost - 文件分离工具
    - kali 不一定自带, `foremost -i 1.png`
- strings
    ```
	strings start.bin | grep -a "pass"
	strings .* | grep -a "root"
	strings -o start.bin 		# 获取所有 ASCII 字符偏移
    ```

**CTF writup**
- [OpenToAll CTF2015 - Gone (Forensics) ](https://ctf.rip/opentoall-ctf2015-gone-forensics/) - 知识点 : ext4修复+AES解密
- [write-ups-2015/opentoall-ctf-2015/forensics/gone at master](https://github.com/ctfs/write-ups-2015/tree/master/opentoall-ctf-2015/forensics/gone) - 同上

## 压缩包

**相关文章**
- [ctf-wiki/zip.md at master · ctf-wiki/ctf-wiki](https://github.com/ctf-wiki/ctf-wiki/blob/master/docs/misc/archive/zip.md)
- [【CTF 攻略】CTF比赛中关于zip的总结](https://www.anquanke.com/post/id/86211)
- [给你压缩包却不给你密码的人到底在想什么](https://veritas501.space/2017/06/23/%E7%BB%99%E4%BD%A0%E5%8E%8B%E7%BC%A9%E5%8C%85%E5%8D%B4%E4%B8%8D%E7%BB%99%E4%BD%A0%E5%AF%86%E7%A0%81%E7%9A%84%E4%BA%BA%E5%88%B0%E5%BA%95%E5%9C%A8%E6%83%B3%E4%BB%80%E4%B9%88/)

### 爆破压缩包

**相关工具**
- [Hashcat](../安全工具/Hashcat.md#爆破压缩包)
- [pyrofex/breakzip](https://gitlab.com/pyrofex/breakzip) - 用于破解使用弱加密的加密压缩文件的实用工具。
- archpr(Advanced Archive Password Recovery) - 一个灵活的，适用于 ZIP 和 RAR 档案的高度优化的口令恢复工具。
- Ziperello - zip 爆破工具
- fcrackzip
    ```
    fcrackzip -v -u -D -p rockyou.txt sample.zip
    -u : use-unzip 有助于误报
    -D ： 选择字典模式
    -p : 选择字典文件
    -v : 详细
    ```
- rarcrack - 支持爆破 rar、zip、7z 三种类型
    ```
    apt install -y rarcrack

    rarcrack aaa.rar --threads 50 --type rar
    rarcrack aaa.7z --threads 50 --type 7z
    ```
- [cRARk for 7-Zip](http://www.crark.net/crark-7zip.html)
- hashcat、John the Ripper
- [7z2hashcat](https://github.com/philsmd/7z2hashcat) - 从受密码保护的.7z存档（和.sfx文件）中提取信息
        ```bash
        # 7z2hashcat.pl 比 7z2john.pl 好用
        ```

### 伪加密

![](../../../assets/img/Security/BlueTeam/取证/1.png)

- 50 4B 03 04 为数据区头文件标记,这里 deFlags 位改为 09 00 可变成伪加密
- 50 4B 01 02 为目录区头文件标记,后面的 deFlags 是加密标记,将 00 00 改为 09 00 可变成伪加密
- 50 4B 05 06 为目录区结束文件标记

### 明文攻击

**相关文章**
- [ZIP明文攻击获得加密压缩包内文件](https://jingyan.baidu.com/article/0f5fb0990bba086d8334eaf6.html)
- [zip加密的明文攻击](https://blog.csdn.net/hustcw98/article/details/82392993)

**相关工具**
- archpr(Advanced Archive Password Recovery)
- [keyunluo/pkcrack](https://github.com/keyunluo/pkcrack)

### CRC32碰撞

![](../../../assets/img/才怪.png)

---

## 视频
### Deegger_Embedder

**相关工具**
- [DeEgger Embedder](http://www.zasi.org/DeEgger-Embedder.php)

---

## 图片

**相关文章**
- [CTF中常见图片隐写](http://zjw.dropsec.xyz/uncategorized/2016/08/18/CTF%E4%B8%AD%E5%B8%B8%E8%A7%81%E5%9B%BE%E7%89%87%E9%9A%90%E5%86%99.html)
- [隐写术总结](http://drops.xmd5.com/static/drops/tips-4862.html)
- [Steganography](http://datagenetics.com/blog/march12012/index.html)
- [misc-stegaBasic](https://www.jianshu.com/p/fe7a5fff2a95)

**在线分析工具**
- [Forensically, free online photo forensics tools](https://29a.ch/photo-forensics/)

**图片隐写通用工具**
- Stegsolve - 隐写图片查看的利器
    - [stegsolve使用方法](https://www.cnblogs.com/cat47/p/11483478.html)
- [stegosuite](https://stegosuite.org/) - 一个用 Java 编写的免费和开源的图片隐写工具。使用 Stegosuite，你可以轻松地隐藏图像文件中的信息。
- [zsteg](https://github.com/zed-0xff/zsteg) - 图片隐写信息快速检测工具
    ```bash
    gem install zsteg
    zsteg 1.png --all
    ```
- [PixelJihad](https://github.com/oakes/PixelJihad) - 一个JavaScript隐写工具

**writup**
- [[IceCTF 2016] [Stega 100 - Pretty Pixels] Write Up](https://0x90r00t.com/2016/08/26/icectf-2016-stega-100-pretty-pixels-write-up/) - 知识点 : 图片隐写

**Tips**
- exif 信息
- 十六进制下搜文件头 `89504E47` 搜文件头数据块 `IHDR`
- strings 查看可见字符
- 有些会修改图片宽高，直接010打开改大点试试
- 2张图试试 xor

---

### LSB隐写

> LSB(英文 least significant bit)即最低有效位，位于二进制数的最右侧。图像的每一个像素点都是由 RGB（红、绿、蓝）三原色组成，每个颜色占8位(如#FFFFFF)。由于修改最后1位对人眼不敏感，这样一个像素点就可以携带3位信息。应用 LSB 算法的图像格式需为无损压缩数据格式，例如图像中的 bmp、png 格式和音频的 wav 格式。

**LSB 隐写专用工具**
- [livz/cloacked-pixel](https://github.com/livz/cloacked-pixel) - LSB 隐写和检测
- [RobinDavid/LSB-Steganography](https://github.com/RobinDavid/LSB-Steganography) - 使用最低有效位将隐写文件转换为图像。

**相关文章**
- [隐写技巧——PNG文件中的LSB隐写](https://3gstudent.github.io/%E9%9A%90%E5%86%99%E6%8A%80%E5%B7%A7-PNG%E6%96%87%E4%BB%B6%E4%B8%AD%E7%9A%84LSB%E9%9A%90%E5%86%99/)

### exif

> 可交换图像文件格式（英语：Exchangeable image file format，官方简称Exif），是专门为数码相机的照片设定的，可以记录数码照片的属性信息和拍摄数据。Exif信息是可以被任意编辑的，因此只有参考的功能。

**相关文章**
- [Explainer: how law enforcement decodes your photos](http://theconversation.com/explainer-how-law-enforcement-decodes-your-photos-78828) - 作者描述了关于数字调查者如何拆解数码照片，寻找关于制造和模型线索的过程。

**相关工具**
- [ExifTool](https://www.sno.phy.queensu.ca/~phil/exiftool/) - 用于读取，写入和编辑各种文件中的 exif 信息的工具
- [EXIF信息查看器](https://exif.tuchong.com/)
- [ExifShot App](https://exifshot.com/app/)
- [如何为老照片添加 Exif 日期数据？](https://www.appinn.com/how-to-add-exif-date-for-old-picture/)

---

## 音频

**音频隐写通用工具**
- [Detect DTMF Tones](http://dialabc.com/sound/detect/index.html) - 分析音频录音，并提供一些统计数字、图表和表格，显示数据中包含了哪些 DTMF 音调，以及在哪里。
- [Audacity](https://sourceforge.net/projects/audacity/) - 一款易于使用的多轨音频编辑器和记录器
- [MP3stego](https://www.petitcolas.net/steganography/mp3stego/) - MP3Stego 将在压缩过程中隐藏 MP3 文件中的信息。

**CTF writup**
- [音频隐写 MP3stego+wav隐写+题目](https://m3tar.github.io/2017/08/20/%E9%9F%B3%E9%A2%91%E9%9A%90%E5%86%99-MP3stego-wav%E9%9A%90%E5%86%99-%E9%A2%98%E7%9B%AE/) - MP3stego+频谱图+猪圈密码

**sstv 音频图像**
- 相关工具
    - [RX-SSTV](http://users.belgacom.net/hamradio/rxsstv.htm)
        - 如果无虚拟输入源,需要下载安装一个 https://vac.muzychenko.net/cn/download.htm

---

## 电子文档

**相关文章**
- [Misc 总结 ----隐写术之电子文档隐写](https://xz.aliyun.com/t/1883)

### Office

**相关文章**
- [PowerPoint — What data is beneath the surface?](https://medium.com/@osint/owerpoint-what-data-is-beneath-the-surface-2eb000ef95fb) - 介绍了几种在ppt中隐藏图片的小技巧
- [如何从 Microsoft Office 文档中完全删除那些暴露你身份的元数据？](https://www.iyouport.org/%e5%a6%82%e4%bd%95%e4%bb%8e-microsoft-office-%e6%96%87%e6%a1%a3%e4%b8%ad%e5%ae%8c%e5%85%a8%e5%88%a0%e9%99%a4%e9%82%a3%e4%ba%9b%e6%9a%b4%e9%9c%b2%e4%bd%a0%e8%ba%ab%e4%bb%bd%e7%9a%84%e5%85%83%e6%95%b0/)

**word 隐藏文本**
- 文件->选项->显示->勾选隐藏文字

![](../../../assets/img/Security/BlueTeam/取证/2.png)

**word、xml 转换**
- 提取信息时,将 word 转化成 xml,查看额外信息
- .doc -> 后缀改为.zip -> 解压 ->.xml

#### 爆破Office加密

**相关工具**
- [Hashcat](../安全工具/Hashcat.md#爆破office)

**破解 ppt**
- 相关工具
    - Advanced Office Password Recovery

### PDF

**PDF 隐写取证工具**
- [PDF Parser](https://github.com/smalot/pdfparser)
    - [Demo | PDF Parser](https://www.pdfparser.org/demo)
- [jesparza/peepdf](https://github.com/jesparza/peepdf)
- [wbStego4.3open](http://www.bailer.at/wbstego/pr_4ix0.htm)
    - wbStego4open 会把插入数据中的每一个 ASCII 码转换为二进制形式，然后把每一个二进制数字再替换为十六进制的 20 或者 09，20 代表 0，09 代表 1。这些转换后的十六进制数据被嵌入到 PDF 文件中。查看用 wbStego4open 修改后的文件内容，会发现文件中已混入了很多由 20 和 09 组成的 8 位字节。

**CTF writup**
- [[XDCTF](MISC)OWASP](https://www.jianshu.com/p/3aaa632ebfea)

#### 爆破PDF加密

**相关文章**
- [使用pdfcrack破解PDF密码(Linux)](http://topspeedsnail.com/crack-pdf-password-use-pdfcrack/)
- [PDF文件密码破解](https://mp.weixin.qq.com/s/EH7Z_mJvuWxtbQdcXf3h4w)

**获取 hash**
- [PDF hash Extractor - instantly](https://www.onlinehashcrack.com/tools-pdf-hash-extractor.php)
- john 的脚本
    ```bash
    cd /usr/share/john/
    ./pdf2john.pl xxx.pdf
    ```

**相关工具**
- [Hashcat](../安全工具/Hashcat.md#爆破pdf文件)

---

# 流量分析

- 内容见 [流量分析](./实验/流量分析.md)

---

# USB取证

- 内容见 [USB取证](./笔记/USB取证.md)

---

# 蓝牙取证

![](../../../assets/img/才怪.png)

---

# 磁盘取证

- 内容见 [磁盘取证](./笔记/磁盘取证.md)

---

# 内存取证

- 内容见 [内存取证](./笔记/内存取证.md)

---

# 应用程序取证

## 远程连接工具取证

**向日葵**
- 向日葵客户端运行过程中的日志文件保存路径: `C:\Program Files (x86)\Oray\SunLogin\SunloginClient\log`
- 向日葵的免安装版会在 `C:\ProgramData\Oray\SunloginClient\` 默认路径下生成 `config.ini` 配置文件，配置文件中的 fastcodehistroy 值以 base64 编码形式存储着向日葵历史连接记录
- [向日葵软件在渗透测试中的应用](https://mp.weixin.qq.com/s/5qzYynZI0bdaUnld0GhA4Q)
- [wafinfo/Sunflower_get_Password](https://github.com/wafinfo/Sunflower_get_Password) - 一款针对向日葵的识别码和验证码提取工具

**xshell**
- xshell 默认是不开启会话日志记录的
- 会话日志文件夹路径 : `C:\Users\<user>\Documents\NetSarang Computer\6\Xshell\Logs`
- 会话文件夹路径 : `C:\Users\<user>\Documents\NetSarang Computer\6\Xshell\Sessions`

**Teamviewer**
- 连接日志文件路径 : `C:\Program Files (x86)\TeamViewer\Connections_incoming.txt`

---

## 浏览器取证

**工具**
- [obsidianforensics/hindsight](https://github.com/obsidianforensics/hindsight) - chrome历史访问记录取证工具(真是不给人留条活路)
- [x899/chrome_password_grabber](https://github.com/x899/chrome_password_grabber) - 从 Chrome 获取未加密的“保存的密码”
- [m0rv4i/SharpCookieMonster](https://github.com/m0rv4i/SharpCookieMonster) - 从 Chrome 中提取 cookie
- [djhohnstein/SharpChromium](https://github.com/djhohnstein/SharpChromium) - 用于从 Chromium 系列浏览器中获取 Cookie、访问历史、网站登录凭据等敏感信息的工具
- [QAX-A-Team/BrowserGhost](https://github.com/QAX-A-Team/BrowserGhost) - 一个抓取浏览器密码的工具
- [wekillpeople/browser-dumpwd](https://github.com/wekillpeople/browser-dumpwd) - 使用 sqlite3 lib 转储浏览器密码（chrome，firefox）。
- [moonD4rk/HackBrowserData](https://github.com/moonD4rk/HackBrowserData) - 一款可全平台运行的浏览器数据导出解密工具。

---

# WEB取证

**文章**
- [比敌人更了解敌人 [ 取证入门 web篇 ]](https://www.freebuf.com/column/147929.html)
- [记一次IIS劫持处置](https://www.freebuf.com/articles/web/222060.html)

---

## 中间件配置

**临时目录**

- IIS
    - IIS 临时压缩文件 : C:\inetpub\temp\IIS Temporary Compressed Files\WEBUI\$^_gzip_D^\WEB\WEBUI\UPLOAD

- Linux
    - `/tmp`

**IIS**

- `C:\Windows\System32\inetsrv\config`

**NGINX**

- 目录 : `/etc/nginx/conf.d/`

**httpd**

- 目录 : `/etc/httpd/conf/`

---

## 中间件服务器程序日志

部分内容来自项目 <sup>[[theLSA/emergency-response-checklist](https://github.com/theLSA/emergency-response-checklist) 和 Tide 团队安全文章]</sup>

**辅助工具**
- [JeffXue/web-log-parser](https://github.com/JeffXue/web-log-parser) - 开源的分析 web 日志工具，采用 python 语言开发，具有灵活的日志格式配置。
- 360星图
- [TurboWay/bigdata_practice](https://github.com/TurboWay/bigdata_practice) - nginx 日志分析可视化

**IIS**

`C:\WINDOWS\system32\LogFiles` : 日志内容包括访问域名时间、ip、访问 url 等信息。

**httpd**
- `/etc/httpd/logs/`

**apache**

apache 日志一般分为 `access_log` 和 `error_log` 两种，通过查看 `httpd.conf` 文件查看 apache 日志路径：
```bash
grep -i "CustomLog" /etc/httpd/conf/httpd.conf
grep -i "ErrorLog" /etc/httpd/conf/httpd.conf
```
- Linux : `/usr/local/apache/logs/`
- Linux : `/var/log/apache2`
- Windows : `apache/logs/`
- `access_log` : 访问日志,记录所有对 apache 服务器进行请求的访问
- `error_log` : 错误日志,记录下任何错误的处理请求，通常服务器出现什么错误，可对该日志进行查看

**nginx**

nginx 的日志主要分为 `access.log`、`error.log` 两种，可通过查看 `nginx.conf` 文件来查找相关日志路径
- `/var/log/nginx/access.log` : 主要记录访问日志，记录访问客户端 ip 地址、访问时间、访问页面等信息。
- `/var/log/nginx/error.log` : 主要记录一些错误信息。

**tomcat**

tomcat 日志默认路径：在安装目录下的 logs 文件夹下
- 如果在安装中默认修改了日志存储位置，可在 `conf/logging.properties` 文件中查看
- `catalina.out` : 运行中的日志，主要记录运行中产生的一些信息，尤其是一些异常错误日志信息
- `catalina.Y-M-D.log` : 是 tomcat 自己运行的一些日志，这些日志还会输出到 `catalina.out`，但是应用向 console 输出的日志不会输出到 `catalina.{yyyy-MM-dd}.log`
- `host-manager.xx.log` : 管理日志
- `localhost.xx.log` : 程序异常没有被捕获的时候抛出的地方，Tomcat 下内部代码丢出的日志(jsp 页面内部错误的异常，`org.apache.jasper.runtime.HttpJspBase.service` 类丢出的，日志信息就在该文件!)应用初始化(listener,filter, servlet)未处理的异常最后被 tomcat 捕获而输出的日志，而这些未处理异常最终会导致应用无法启动。
- `manager.xx.log`
- `localhost_access_log` : 主要记录访问日志信息，记录访问的的时间、ip 地址等信息，也是应急中经常用到的日志信息

**weblogic**

weblogic 在安装结束后默认开启了日志记录功能，默认配置情况下，weblogic 会有3种日志，分别是 `accesslog`, `Server log` 和 `domain log`，WebLogic8.x 和 9 及以后的版本目录结构有所不同。

- `domain_name/servers/server_name/logs/`
- `$MW_HOME` 是 WebLogic 的安装目录
- `<domain_name>` 是域的实际名称，是在创建域的时候指定的
- `<server_name>` 是 Server 的实际名称，是在创建 Server 的时候指定的
- `<adminserver_name>` 是 Admin Server 的实际名称，是在创建 Admin Server 的时候指定的。

WebLogic 9及以后版本：
- `domain log` : 主要记录了一个 domain 的运行情况，一个 domain 中的各个 weblogic server 可以把它们的一些信息（如：严重错误）发送到 AdminServer 上，AdminServer 把这些信息传递到 domain.log 上.
    ```
    $MW_HOME\user_projects\domains\<domain_name>\servers\<adminserver_name>\logs\<domain_name>.log
    ```
- `server log` : 主要用于服务器的一般日志记录，比如 weblogic 的启动、关闭、部署应用等相关记录，日志格式：依次为时间戳，严重程度，子系统，计算机名，服务器名，线程 ID.
    ```
    $MW_HOME\user_projects\domains\<domain_name>\servers\<server_name>\logs\<server_name>.log
    ```
- `access log` : 主要记录 http 请求，默认情况下日志记录处于启用状态，服务器将 http 请求保存在单独的日志文件中，日志主要记录了 http 请求请求 ip 地址、请求时间、访问页面、响应状态等信息.
    ```
    $MW_HOME\user_projects\domains\<domain_name>\servers\<server_name>\logs\access.log
    ```

WebLogic 8.x版本:
- `access log`
    ```
    $MW_HOME\user_projects\domains\<domain_name>\<server_name>\access.log
    ```
- `server log`
    ```
    $MW_HOME\user_projects\domains\<domain_name>\<server_name>\<server_name>.log
    ```
- `domain log`
    ```
    $MW_HOME\user_projects\domains\<domain_name>\<domain_name>.log
    ```

**jboss**
- LOG4J 配置默认 `Deploy/conf/` 如 `jboss/server/default/conf/jboss-log4j.xml`

---

# 数据库取证

部分内容来自项目 <sup>[[theLSA/emergency-response-checklist](https://github.com/theLSA/emergency-response-checklist) 和 Tide 团队安全文章]</sup>

**misc**
- `mysql\lib\plugin` 目录的异常文件
- select * from mysql.func 的异常
- mssql 检查 xp_cmdshell 等存储过程
- 异常数据库登录
- 数据库用户弱口令
- 注意 mysqld 配置文件

---

## mysql

**mysql 日志**
- 错误日志：默认开启，hostname.err
- 查询日志：记录用户的所有操作。默认关闭，general_log_file（常见 getshell 手法）
- 慢查询日志：记录执行时间超过指定时间的查询语句，slow_query_log_file（慢查询 getshell）
- 事务日志：ib_logfile0
- 二进制日志：记录修改数据或有可能引起数据改变的 mysql 语句，log_bin，默认在数据目录，如 mysql-bin.000001
- `ErrorLog` : 记录 Mysql 运行过程中的 Error、Warning、Note 等信息，系统出错或者某条记录出问题可以查看 Error 日志；
- `GenaralQuery Log` ：记录 mysql 的日常日志，包括查询、修改、更新等的每条 sql；
    ```sql
    show variables like '%general%';        -- 查看log配置信息
    SET GLOBAL general_log = 'On';          -- 开启日志
    SET GLOBAL general_log_file = '/var/lib/mysql/mysql.log';  -- 指定日志文件路径
    ```
- `Binary Log` ：二进制日志，包含一些事件，这些事件描述了数据库的改动，如建表、数据改动等，主要用于备份恢复、回滚操作等；
- `Slow QueryLog*` ：记录 Mysql 慢查询的日志；
- mysql 相关命令
    ```sql
    status;
    show global variables like '%log%';
    show global variables like '%gene%';
    show master status;
    systemmore /mydata/data/stu18_slow.log;
    showbinary logs;
    showmaster logs;
    showbinlog events in 'mysql-bin.000011';
    show processlist;
    ```
- 更多 mysql 日志类型可参考 https://www.jianshu.com/p/db19a1d384bc
- 有哪些IP在爆破？
    ```bash
    grep  "Access denied" mysql.log |cut -d "'" -f4|uniq -c|sort -nr
    ```
- 爆破用户名字典都有哪些？
    ```bash
    grep  "Access denied" mysql.log |cut -d "'" -f2|uniq -c|sort -nr
    ```

---

## mssql

**mssql 日志**

SQL Server 日志记录了完整的 SQL Server 数据库运行的状态信息，并以消息的形式记录系统级、应用级操作。

可以使用 SQL Server Management Studio 中的日志文件查看器来访问有关在以下日志中捕获的错误和事件的信息：

SQL Server Management Studio 连接 sqlserver 数据库，查看与常规 SQL Server 活动相关的日志。

登录到 SQL Server Management Studio，依次点击 管理--SQL Server 日志

- exec xp_readerrorlog
- object Explorer-Management-SQL Server logs-view-logs
- SQL Server 2008： R2\MSSQL10_50.MSSQLSERVER\MSSQL\Log\ERRORLOG
- 查询最近一次启动 sqlserver 时间：
    ```sql
    select sqlserver_start_time fromsys.dm_os_sys_info;
    ```
- 历史 sql 记录查询：SQLServer 并没有这样的实现，只有 `sys.dm_exec_query_stats` 缓存了一部分 (sql server 服务开启后执行的语句，某些不被缓存执行计划的语句并不记录)。
- Sqlserver 开启日志审计功能可参考 https://blog.51cto.com/gaowenlong/1908381

- xp_cmdshell在mssql2005之后的版本中是默认禁止的，查看xp_cmdshell是否被启用。
    ```
    Exec master.dbo.xp_cmdshell 'whoami'
    ```

---

## Oracle

**Oracle 日志**
- 查看日志 : SQL> show parameter dump
- 查看 v$diag_info 系统视图 : SQL> select * from v$diag_info;
- 查询 bdump 参数，来找到 alert 日志位置 : show parameter background_dump_dest

Oracle 日志文件分为两种：重做日志文件（redo log file）、归档日志文件，其中重做日志文件主要记录了数据库的操作过程，可以在进行数据库恢复时，将重做日志文件在还原的数据库上进行执行，以达到数据库的最新状态。

Oracle 数据库默认只是对数据库的登录情况记录，但是不对数据库的查询记录统计，可通过 `show parameter audit`，查看审计功能是否开启，若 audit_sys_operations 值为 DB。

开启审计功能
```
alter system set audit_sys_operations=TRUEscope=spfile;
alter system set audit_trail=db,extendedscope=spfile;
```
重启实例即可,开启后会把审计内容记录到 sys 库的 `AUD$` 表中

数据库连接日志
```
cat /opt/oracle/diag/tnslsnr/localhost/listener/trace/listener.log
```
