LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 05-08-2014, 10:47 PM   #1
Linux_Kidd
Member
 
Registered: Jan 2006
Location: USA
Posts: 539

Rep: Reputation: 51
URL w/ Hex


i need some help. using perl, is there a way to specify an actual hex char to be used in a URL, like 0x20

an HTTP GET that has %20 in the uri is actually three hex chars and is the HTTP equiv of a space. but is there a way to represent a "space" using a hex value of say 0x20 or 0x00?

as example (which doesnt work, the actual GET has "$char" in it).

Code:
#!C:/perl64/bin/perl -w
#use strict;
use warnings;
use LWP::UserAgent [search.cpan.org];
use HTTP::Request [kobesearch.cpan.org];
my $char = "\x20"; # hexadecimal
my $URL = 'http://www.xyz.com/xxx/search/?o=nav&sp=cowboys$charand$charindians';

Last edited by Linux_Kidd; 05-08-2014 at 11:10 PM.
 
Old 05-09-2014, 12:39 AM   #2
ndc85430
Member
 
Registered: Apr 2014
Distribution: Slackware
Posts: 77

Rep: Reputation: Disabled
Can you explain in more detail what it is you want to do and why? Certain characters (like space) need to be percent-encoded in the query part of the URL. See this and references therein.
 
Old 05-09-2014, 09:54 AM   #3
Linux_Kidd
Member
 
Registered: Jan 2006
Location: USA
Posts: 539

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by ndc85430 View Post
Can you explain in more detail what it is you want to do and why? Certain characters (like space) need to be percent-encoded in the query part of the URL. See this and references therein.
i think you are noting the rules..... doesnt mean i cant send 0x20 instead of 0x25,0x32,0x30

i am investigating a WAF log violation which shows the URL with actual spaces. the WAF itself wont show what the actual space is in hex. for normal URL's using url encoding like %20 the WAF shows these (which are three ascii chars of %, 2, and 0), etc.

i want to be able to send 0x20 instead of using %, etc.
 
Old 05-09-2014, 10:36 AM   #4
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,543

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Okay, so you want to send
Code:
http://www.xyz.com/xxx/search/?o=nav&sp=cowboys and indians
instead of
Code:
http://www.xyz.com/xxx/search/?o=nav&sp=cowboys%20and%20indians
?

Quote:
Originally Posted by Linux_Kidd
as example (which doesnt work, the actual GET has "$char" in it).
That's just a string interpolation problem, use double quotes instead of single quotes around the url, see Strings in Perl: quoted, interpolated and escaped.

Quote:
but is there a way to represent a "space" using a hex value of say 0x20 or 0x00?
0x00 doesn't represent space (in any existing encoding), so that doesn't quite make sense.
 
Old 05-09-2014, 12:11 PM   #5
Linux_Kidd
Member
 
Registered: Jan 2006
Location: USA
Posts: 539

Original Poster
Rep: Reputation: 51
yes, in general thats what i am trying to do. browsers (url encoders in general) will swap out ascii space for %20, etc. i tried %00 and webserver handled it a different way vs using %20, %00 gave http302 while %20 gave http200.

0x00 is null char, which is still 1 byte in the uri.
0x00 or 0x20 is 1 byte in the data, what the app layer does with 0x00 or non 0x20 is TBD.

Last edited by Linux_Kidd; 05-09-2014 at 12:14 PM.
 
Old 05-09-2014, 04:58 PM   #6
Linux_Kidd
Member
 
Registered: Jan 2006
Location: USA
Posts: 539

Original Poster
Rep: Reputation: 51
it seems like the perl module used for getting the URL handles it oddly
Code:
my $URL = "http://www.xyz.com/xxx/search/?o=nav&sp=cowboys$charand$charindians";
shows this on the wire
GET /xxx/search/?o=nav&sp=cowboys HTTP/1.1

same for any hex value, it simply truncates it off after "cowboys"

any way via perl to achieve this, or do i need to resort to using a raw packet gen?

Last edited by Linux_Kidd; 05-09-2014 at 05:01 PM.
 
Old 05-09-2014, 06:10 PM   #7
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,543

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Oh, you need braces too:

Code:
my $URL = "http://www.xyz.com/xxx/search/?o=nav&sp=cowboys${char}and${char}indians";
 
Old 05-10-2014, 10:16 AM   #8
Linux_Kidd
Member
 
Registered: Jan 2006
Location: USA
Posts: 539

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by ntubski View Post
Oh, you need braces too:

Code:
my $URL = "http://www.xyz.com/xxx/search/?o=nav&sp=cowboys${char}and${char}indians";
ok, braces added, but on the wire the URL module replaces the ${char} with a %

Code:
GET /xxx/search/?o=nav&sp=cowboys%and%indians HTTP/1.1
is there a better URL module to use ??
 
Old 05-12-2014, 09:00 AM   #9
Linux_Kidd
Member
 
Registered: Jan 2006
Location: USA
Posts: 539

Original Poster
Rep: Reputation: 51
my bad on my last post.

of course i was seeing %, i was using \x25 for the hex char
however, a \x20 simply shows %20 in the get query, looks like the url module is encoding the space char into its HTTP %20 equiv.

any ideas ??
 
Old 05-12-2014, 11:41 AM   #10
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian
Posts: 2,543

Rep: Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879Reputation: 879
Use a TCP level library I guess? I don't know perl well enough to give more specific suggestions.
 
Old 05-18-2014, 01:41 PM   #11
trbennett48
LQ Newbie
 
Registered: Apr 2011
Posts: 23

Rep: Reputation: 3
If you want to put the "value" of "$char" into the
string then this should work for you:

Code:
my $char = "\x20";

my $URL = "http://www.xyz.com/xxx/search/?o=nav&sp=cowboys"
          . $char
          . "and"
          . $char
          . "indians";

printf("-->%s<--\n", $URL);
However if you want to "URI encode" your URI then look at this
link which describes the perl module that will do it for you:

http://www.perlhowto.com/encode_and_decode_url_strings
 
Old 05-19-2014, 12:42 PM   #12
Linux_Kidd
Member
 
Registered: Jan 2006
Location: USA
Posts: 539

Original Poster
Rep: Reputation: 51
Quote:
Originally Posted by trbennett48 View Post
If you want to put the "value" of "$char" into the
string then this should work for you:

Code:
my $char = "\x20";

my $URL = "http://www.xyz.com/xxx/search/?o=nav&sp=cowboys"
          . $char
          . "and"
          . $char
          . "indians";

printf("-->%s<--\n", $URL);
However if you want to "URI encode" your URI then look at this
link which describes the perl module that will do it for you:

http://www.perlhowto.com/encode_and_decode_url_strings
URI encoders want to convert any hex 0x20 into three chars of %20, etc. Thats exactly what i am trying to get around. i need a URL encoder that will write the wire exactly as stated, in my case using a single 0x20 hex char for the space, etc.
 
Old 05-21-2014, 07:51 AM   #13
ndc85430
Member
 
Registered: Apr 2014
Distribution: Slackware
Posts: 77

Rep: Reputation: Disabled
The client is supposed to URL encode the query string. If you want to do things differently, you'll possibly have to use another (your own?) protocol. Naturally, the thing doing the receiving will have to change as well.

You haven't said what this is for. Perhaps there's a better way to accomplish your end goal.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Redirect with URL not showing the new redirects URL link Apache RHEL 6 gdizzle Linux - Newbie 4 12-03-2013 04:09 AM
Passable nouveau kernel driver bug (MMIO read of [hex l] FAULT at [hex l]) marbangens Linux - General 1 05-24-2013 02:35 AM
Squid ACL to allow access to a child URL below a blocked main URL soslinux Linux - Server 1 10-13-2011 03:47 AM
Firefox 2.0.0.14 on Mandrake 10.1 will not load hex-dec url's Toadman Linux - Software 1 06-20-2008 10:03 PM
Hex output of a hex/ascii input string mlewis Programming 35 04-10-2008 01:05 PM


All times are GMT -5. The time now is 12:55 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration