Hack Forums
[Python] String to non-alphanumerical PHP code Converter - Printable Version

+- Hack Forums (https://hackforums.net)
+-- Forum: Tech (https://hackforums.net/forumdisplay.php?fid=444)
+--- Forum: Coding (https://hackforums.net/forumdisplay.php?fid=151)
+---- Forum: Software Development (https://hackforums.net/forumdisplay.php?fid=118)
+---- Thread: [Python] String to non-alphanumerical PHP code Converter (/showthread.php?tid=5292895)



String to non-alphanumerical PHP code Converter - .trigious - Jun 4, 2016

Hey.

I don't know how, but I somehow stumbled upon this tutorial on how to write non-alphanumerical PHP code.

I wasn't sure if a script that converts strings to said code was posted here before. If someone did, I certainly did not invent this technique or so.
I made the script to speed up the process of writing such code and thought I'd share it here.



Example call:
Code
/home//code/python/rce/nonalpha.py phpinfo
Output:
Code
('.' ^ '^').('@' ^ '(').('.' ^ '^').('@' ^ ')').('@' ^ '.').('@' ^ '&').('@' ^ '/')



If you have no idea what the code does, just read the tutorial and it should be clear.

Peace


* - SIM-1866423 - Jun 4, 2016

Yup i did same thing before, was fun.If you dont mind, i change yours just little bit (:

PHP Code

<?php 
#!/usr/bin/python3.4
import sys
from random import choice
 
# define non alpha characters
nonalpha = '^!"$%&/{([)]=}?\\`*+~\'#-_.:,;<>|@'
 
 
# xor characters and return output
def do_xor(char):
    
result = ["('"+x+"')." for x in nonalpha if chr(ord(char) ^ ord(x)) in nonalpha]
    if 
result:
        return 
choice(result)
    else:
        
sys.exit("Unable to convert string into non-alphanumerical representation")
 

if 
len(sys.argv) != 2:
    
sys.exit("Usage: python " + sys.argv[0] + " input_string")
else:
    print 
"".join([do_xor(x) for x in sys.argv[1] if do_xor(x)])[:-1] 



* - █BORNE█ - Jun 4, 2016

Mind explaining what this does?


* - .trigious - Jun 4, 2016

(Jun 4, 2016 05:34 AM)OneBongWill Wrote:  Mind explaining what this does?

I refered to a tutorial in the thread.
However, I found the PHP manual very helpful.

http://php.net/manual/en/language.operators.bitwise.php

Search for the part about XOR on strings. :)