Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

I am trying to create a bash script that allows me to make a POST request to authenticate a client on a local firewall. The firewall has a web client to authenticate and after that, the client is allowed to make network requests on most ports, otherwise only port 80 is allowed.

The following PHP/CURL code works fine but isn't enough since most systems are servers that don't have PHP or CURL installed:


$aFields = array ( 'fw_username' => 'username', 'fw_password' => 'password', 'fw_domain' => 'Firebox-DB', 'submit' => 'Login', 'action' =>  'fw_logon', 'style' => 'fw_logon_progress.xsl', 'fw_logon_type' => 'logon' );
$sFields = "";
foreach( $aFields as $key=>$value ) 
        $sFields .= "$key=$value&";
rtrim( $sFields, '&' );
$oCurl = curl_init();
curl_setopt( $oCurl, CURLOPT_URL, "" );
curl_setopt( $oCurl, CURLOPT_POST, count( $aFields ) );
curl_setopt( $oCurl, CURLOPT_POSTFIELDS, $sFields );
curl_setopt( $oCurl, CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $oCurl, CURLOPT_SSL_VERIFYHOST, false );
curl_setopt( $oCurl, CURLOPT_RETURNTRANSFER, true );
curl_setopt( $oCurl, CURLOPT_HEADER, true );
curl_setopt( $oCurl, CURLINFO_HEADER_OUT, true );
curl_setopt( $oCurl, CURLOPT_VERBOSE, true );
curl_exec( $oCurl );

echo curl_getinfo( $oCurl, CURLINFO_HEADER_OUT );

curl_close( $oCurl );

I have tried to recreate this request using the openssl s_client command but that doesn't seem to work:

[root@STAGIARPC henk]# cat request.txt | openssl s_client -connect              
depth=0 O = WatchGuard, OU = Fireware, CN = Fireware web CA
verify error:num=18:self signed certificate
verify return:1
depth=0 O = WatchGuard, OU = Fireware, CN = Fireware web CA
verify return:1
Certificate chain
 0 s:/O=WatchGuard/OU=Fireware/CN=Fireware web CA
   i:/O=WatchGuard/OU=Fireware/CN=Fireware web CA
Server certificate
subject=/O=WatchGuard/OU=Fireware/CN=Fireware web CA
issuer=/O=WatchGuard/OU=Fireware/CN=Fireware web CA
No client certificate CA names sent
SSL handshake has read 1233 bytes and written 646 bytes
New, TLSv1/SSLv3, Cipher is AES256-SHA
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: zlib compression
Expansion: zlib compression
    Protocol  : TLSv1
    Cipher    : AES256-SHA
    Session-ID: 3513D415A58EE1ABE20DB4BEC7948D66E324B8E44866E04AD7BCFB3D3BE374E4
    Master-Key: C003B67841D67EB5BBD0FB0F0A525D79ACDE91F580CB2A9C2C683E1210E7AF538282AE1D8486A19A9EF850C2B7AA28AF
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    TLS session ticket:
    0000 - d1 e9 89 1f ab 8d 68 f3-cf 48 c7 89 7f 60 fc 59   ......h..H...`.Y
    0010 - 52 da 75 3d 41 f2 62 1f-0e a7 e4 ec 19 5e 68 f0   R.u=A.b......^h.
    0020 - 45 08 d6 54 76 d7 d3 95-a7 7b 94 b7 52 f0 7d 3e   E..Tv....{..R.}>
    0030 - c7 cd 9a 81 67 eb 2f e9-51 44 f5 06 9a 50 f8 50   ....g./.QD...P.P
    0040 - a4 7c 34 7b 72 98 67 90-61 bc fb 31 e5 1c e8 54   .|4{r.g.a..1...T
    0050 - 2a 6d ca f6 04 e2 6f f7-db a6 7d 6b 7a 61 df b0   *m....o...}kza..
    0060 - e9 44 04 dc 8f 8a 7c 34-1e 21 10 46 3c 94 04 c8   .D....|4.!.F<...
    0070 - 92 7c ca 19 91 4c d0 1b-05 e7 fc 75 49 a3 6a 00   .|...L.....uI.j.
    0080 - 09 ca ca 51 c1 e9 e6 7f-b9 8d 89 5e dc 45 25 4c   ...Q.......^.E%L
    0090 - b7 c6 54 33 b0 3c de 14-74 4a 40 ab 6e 52 0e f8   ..T3.<..tJ@.nR..

    Compression: 1 (zlib compression)
    Start Time: 1395153408
    Timeout   : 300 (sec)
    Verify return code: 18 (self signed certificate)
[root@STAGIARPC henk]# 

Of course, I expected a complete HTTP response, but instead it simply stops with 'DONE'. I think the reason for this is these lines:

Compression: zlib compression
Expansion: zlib compression

But I'm unsure how to make the openssl s_client use zlib compression for this. Can anyone help me out?

These are the contents of request.txt:

Connection: keep-alive
Content-Length: 882
Cache-Control: max-age=0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.154 Safari/537.36
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryBMjY0UHEyASdwrIw
DNT: 1
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8,nl;q=0.6
Cookie: domain=null; username=username
X-CookiesOK: I explicitly accept all cookies

Content-Disposition: form-data; name="fw_username"

Content-Disposition: form-data; name="fw_password"

Content-Disposition: form-data; name="fw_domain"

Content-Disposition: form-data; name="fw_domain"

Content-Disposition: form-data; name="submit"

Content-Disposition: form-data; name="action"

Content-Disposition: form-data; name="style"

Content-Disposition: form-data; name="fw_logon_type"


Thanks in advance!

share|improve this question

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.