Author Topic: Changing HTTP response header  (Read 3069 times)

0 Members and 1 Guest are viewing this topic.

Offline LeoNeeson

  • Tireless poster
  • ****
  • Posts: 579
  • Solitario...
    • View Profile
    • twitter.com/LeoNeeson
Changing HTTP response header
« on: May 22, 2016, 09:36:06 AM »
OK, I've started a new thread to keep this organized. This post started here, and the question was: How to change the HTTP response header "Server" (or any other string in the header) using Macros? ("Server" is a string that displays the name of the server, and it shows the HFS version). If you don't know what I'm talking about, use a Download Manager that show this info (for example, I'm using FlashGet).

Suggestions and examples are welcome. :)
HFS in Spanish (HFS en Español) / How to compile HFS (Tutorial)
• I'm open to help and share any file you may need (just ask me) ;)

Offline LeoNeeson

  • Tireless poster
  • ****
  • Posts: 579
  • Solitario...
    • View Profile
    • twitter.com/LeoNeeson
Re: Changing HTTP response header
« Reply #1 on: May 22, 2016, 09:45:26 AM »
@Mars: Using your macro code, here are my tests. I edit the default template, by going to Menu > HTML Template > Edit... using HFS in Expert mode (or by pressing F6). Then, I put your code after this:

Code: [Select]
[+special:strings]
option.paged=1
COMMENT this option causes your file list to be paged by default

And also tried to put it in [special:begin] but it was the same.

In your code, I've changed what is marked in red here (just for testing):

Quote
    if name = 'HFS' then
      if satisfied(md.cd) then
        begin
        result:='Apache';

...and the result is: this is not working. :-\

I guess this is because I'm inserting your code in a wrong place, or because what I've changed was not right. It would be great if you have an example or say me WHERE to put your code, and WHAT to change (marking it in red).

Thank you. :)
« Last Edit: May 22, 2016, 09:54:02 AM by LeoNeeson »
HFS in Spanish (HFS en Español) / How to compile HFS (Tutorial)
• I'm open to help and share any file you may need (just ask me) ;)

Offline bmartino1

  • Tireless poster
  • ****
  • Posts: 861
  • I'm only trying to help i mean no offense.
    • View Profile
    • My HFS Google Drive Shared Link
Re: Changing HTTP response header
« Reply #2 on: May 22, 2016, 06:18:44 PM »
http://www.rejetto.com/wiki/index.php?title=HFS:_scripting_commands

it looks like your were trying to run a program on the satisfied string/Boolean value...

i would assume that execute will be played here...

from what i learned and what has been found on the forum by other users, the special string

Code: [Select]
[+special:strings]
option.paged=1
COMMENT this option causes your file list to be paged by default

Goes into the default template for all sites, or the (house) root properties "different template tab" of a folder...

so it also looks like your trying to start and stop an Apache sided server (to fulfill) plugins when a specific request is sent. so make HFS have all its tricks, but when something like php, have it switch to Apache...) something like that...

either way, i think mars/rejeto/silentplz/raybob would be better help for you in regards to scripting at a certain request...
I believe that is something that has to be made in the source, not the macro scripts or the templates...
« Last Edit: May 22, 2016, 06:23:40 PM by bmartino1 »
I'm only trying to help i mean no offense.
thank you for your time and patience,
Bmartino1

Offline LeoNeeson

  • Tireless poster
  • ****
  • Posts: 579
  • Solitario...
    • View Profile
    • twitter.com/LeoNeeson
Re: Changing HTTP response header
« Reply #3 on: May 23, 2016, 08:44:41 AM »
Thanks bmartino1, but no, it doesn't have anything to do with Apache or running a program. This is how HFS identifies itself when someone get/download a file from our server. This is also being called as Server Signature (similar to browser's User Agent). This is a HTTP header value.

When some does a HTTP request to a file, HFS identifies itself as:
Code: [Select]
Server: HFS 2.3h
The same way, Apache server identifies itself as:
Code: [Select]
Server: Apache/2.2.17 (Win32) PHP/5.2.17
You may wonder why you may want to change this? The answer is simple: "just for fun" or "to protect our server" (since each version -of almost any server- has some deficiencies that could be exploited, and a hacker who knows your version number may benefit from it by focused attacks). You may read about this here (they talk there about Apache in that article, but the "server signature" also exist on HFS, and on almost every server).

You can test any Server Signature here: http://security.firewallmonitor.org/

Well, I expect mars/rejetto/silentplz/raybob have an answer for this, I mean a macro to change this value (or any other HTTP header value). :)
HFS in Spanish (HFS en Español) / How to compile HFS (Tutorial)
• I'm open to help and share any file you may need (just ask me) ;)

Follow members gave a thank to your post:


Offline Mars

  • Operator
  • Tireless poster
  • *****
  • Posts: 1880
    • View Profile
Re: Changing HTTP response header
« Reply #4 on: May 25, 2016, 08:32:29 PM »
How to change the HTTP response header "Server" (or any other string in the header) using Macros?

After unsuccessfully sought an outcome by changing the Delphi code, it appeared that the solution was simple.
anywhere in the template, it is possible to add a header using a macro as follows model

{.add header|A: B, C, D.}

an example give Cache-Control: no-cache, no-store, must-revalidate, max-age=-1

if a previous header exist as  A: F then the final header become A: F, B, C, D

using macro {.add header|Server: APACHE.} give as result Server: HFS 2.3h, APACHE

if you want to remove this HFS + version that annoy you, this is not feasible using a macro

go to menu > other options, and uncheck "Send HFS Identifier"

 8) 8)

Follow members gave a thank to your post:


Offline LeoNeeson

  • Tireless poster
  • ****
  • Posts: 579
  • Solitario...
    • View Profile
    • twitter.com/LeoNeeson
Re: Changing HTTP response header
« Reply #5 on: May 26, 2016, 10:48:05 AM »
go to menu > other options, and uncheck "Send HFS Identifier"
Tested and working! 8)

anywhere in the template, it is possible to add a header using a macro as follows model
using macro {.add header|Server: APACHE.} give as result Server: HFS 2.3h, APACHE
That doesn't work... :-\

Adding this {.add header|Server: Apache.} or any other string, doesn't have any effect on the HTTP header.

Where do you added? (have you tested it?). You said "any place" in the template, but it doesn't work if I put it anywhere. I've tested having the "Send HFS Identifier" option enabled and disabled, but it's the same. I've tried putting that in the [special:begin] section, but it's the same. Reading the Wiki, it should work, but it doesn't.
HFS in Spanish (HFS en Español) / How to compile HFS (Tutorial)
• I'm open to help and share any file you may need (just ask me) ;)

Offline Mars

  • Operator
  • Tireless poster
  • *****
  • Posts: 1880
    • View Profile
Re: Changing HTTP response header
« Reply #6 on: May 26, 2016, 12:47:21 PM »
I'm watching the headers send by HFS using the plugin HttpFox under Firefox and the macro behavior is correct, tested with default template of hfs 2.3h

it seems that occasionally the added header is not effective. to check its proper implementation I included in a log macro

Code: [Select]
[+]
{.add to log|{.add header|Server:APACHE.}Macro ADD HEADER executed.}

HFS log:
14:45:23 127.0.0.1:1846 Macro ADD HEADER executed

HttpFox report:
(Status-Line)   HTTP/1.1 200 OK
Content-Type   text/html
Content-Length   2104
Accept-Ranges   bytes
Cache-Control   no-cache, no-store, must-revalidate, max-age=-1
Server   APACHE
Content-Encoding   gzip

Offline LeoNeeson

  • Tireless poster
  • ****
  • Posts: 579
  • Solitario...
    • View Profile
    • twitter.com/LeoNeeson
Re: Changing HTTP response header
« Reply #7 on: May 27, 2016, 05:40:05 AM »
Code: [Select]
[+]
{.add to log|{.add header|Server:APACHE.}Macro ADD HEADER executed.}
It's very odd, it doesn't even get that logged ("Macro ADD HEADER executed" is not showing in the HFS log). I've added your code before [+special:strings] and tried several times, saving and restarting HFS, but it's not working and that text is not shown in the logs. Maybe it's because I'm using Windows XP?... ???

Tested using HttpFox and FlashGet, but that text ("Macro ADD HEADER executed") doesn't get logged. And it should get logged if the macro is executed, right?... Very strange... :-\

Here's the HttpFox report:
Code: [Select]
(Status-Line) HTTP/1.1 200 OK
Content-Type application/octet-stream
Content-Range bytes 25305088-25305813/25305814
Content-Length 726
Accept-Ranges bytes
Server HFS 2.3h
Last-Modified Fri, 22 Jan 2016 09:35:26 GMT
Content-Disposition attachment; filename="Test.rar";

HFS log:
Quote
22:15:25 127.0.0.1:1776 Requested GET /Folder/Test.rar
22:15:25 127.0.0.1:1776 Fully downloaded - 726 @ 44.3 KB/s - /Folder/Test.rar

Well, don't worry, maybe it's easier if Rejetto add an option in the HFS.ini to customize the Server name (and the cookie name). But that's if he wants and have free time (since it's not an important feature). :)

Thank you anyway Mars.
If anyone comes with another macro solution (or where to write it), it's welcome.

Cheers,
Leo.-
HFS in Spanish (HFS en Español) / How to compile HFS (Tutorial)
• I'm open to help and share any file you may need (just ask me) ;)

Offline Mars

  • Operator
  • Tireless poster
  • *****
  • Posts: 1880
    • View Profile
Re: Changing HTTP response header
« Reply #8 on: May 27, 2016, 01:51:43 PM »
Code: [Select]
[+]
{.add to log|{.add header|Server:APACHE.}Macro ADD HEADER executed.}

a section named [A] may have several sections called [+ A], but those should be placed after this one

Code: [Select]
[] is the main section, his child section
Code: [Select]
[+ ] must be added  after this one in the template,  never before otherwise it will be ignored

Quote
Tested using HttpFox and FlashGet, but that text ("Macro ADD HEADER executed") doesn't get logged. And it should get logged if the macro is executed, right?... Very strange... :-\

I found the same problem, I guess you have edited the template using the F6 key from HFS, which runs NP ++,

this is not the best way because as it NP++ causes loss of hfs.tpl file is renamed to a temporary file by np ++, then hfs uses the internal default template

I suggest you to edit the template directly by loading the file  hfs.tpl in NP ++, each refresh of web page force HFS to nalysis the file date to determine whether an update of the model was carried out and if it does recharge it the file to replace the model cached
----------
HFS has a light youthful fault with headers, I have a solution but I must expose the problem to Rejetto to correct it and extend the functionality of the ADD HEADER macro, so that its functioning is correct.

PS:
Look at your mailbox sending a zip (template + exe) passed trough virscan.org without virus  ;)
« Last Edit: May 27, 2016, 02:27:33 PM by Mars »

Offline LeoNeeson

  • Tireless poster
  • ****
  • Posts: 579
  • Solitario...
    • View Profile
    • twitter.com/LeoNeeson
Re: Changing HTTP response header
« Reply #9 on: May 28, 2016, 07:18:54 AM »
a section named [A] may have several sections called [+ A], but those should be placed after this one
Good to know, I didn't know that.

I found the same problem, I guess you have edited the template using the F6 key from HFS, which runs NP ++,
That's right, I was using F6 to edit the template. From now on, I'll close HFS first, and then I'll open the template with NP++, to be sure.

HFS has a light youthful fault with headers, I have a solution but I must expose the problem to Rejetto to correct it and extend the functionality of the ADD HEADER macro, so that its functioning is correct.

PS:
Look at your mailbox sending a zip (template + exe) passed trough virscan.org without virus  ;)
Good. (I guess this message was for Rejetto, right?)
HFS in Spanish (HFS en Español) / How to compile HFS (Tutorial)
• I'm open to help and share any file you may need (just ask me) ;)

Offline LeoNeeson

  • Tireless poster
  • ****
  • Posts: 579
  • Solitario...
    • View Profile
    • twitter.com/LeoNeeson
Re: Changing HTTP response header
« Reply #10 on: June 03, 2016, 09:42:17 AM »
Are there any news on this?...
HFS in Spanish (HFS en Español) / How to compile HFS (Tutorial)
• I'm open to help and share any file you may need (just ask me) ;)

Offline Mars

  • Operator
  • Tireless poster
  • *****
  • Posts: 1880
    • View Profile
Re: Changing HTTP response header
« Reply #11 on: June 03, 2016, 08:33:33 PM »
Have a look at this beta version ;)

NOTE:
Specially to have the head 'Server: HFS 2.3' replaced by the desired value in all reply requests, do not add it into the template, but put it in the events file hfs.events at section
Code: [Select]
[pre-filter-request]
{.add header|Server:HFS LeoNeeson.}
« Last Edit: June 04, 2016, 08:03:06 AM by Mars »

Follow members gave a thank to your post:


Offline LeoNeeson

  • Tireless poster
  • ****
  • Posts: 579
  • Solitario...
    • View Profile
    • twitter.com/LeoNeeson
Re: Changing HTTP response header
« Reply #12 on: June 04, 2016, 05:25:55 AM »
Cool! It's working perfect! :D

I don't know what you changed in the source code, but you should submit the changes to Rejetto, so he can include it in the next version. Nice work!.
HFS in Spanish (HFS en Español) / How to compile HFS (Tutorial)
• I'm open to help and share any file you may need (just ask me) ;)