Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Block empty user agent with URLScan

I'm able to block a specific user agent, but I'd like to block all requests with an empty user agent using URLscan v3.1.

Does anyone know how to do this?

like image 886
Reto Avatar asked Sep 22 '10 17:09

Reto


1 Answers

There isn't a way to configure this using URLScan, but it can be done with a custom ISAPI filter on your IIS server. Here it is in C++:

DWORD WINAPI __stdcall HttpFilterProc(HTTP_FILTER_CONTEXT *pfc, DWORD NotificationType, VOID *pvData) 
{ 
    char buffer[256];
    DWORD buffSize = sizeof(buffer);
    HTTP_FILTER_PREPROC_HEADERS *p;
    switch (NotificationType)  {
      case SF_NOTIFY_PREPROC_HEADERS :
      p = (HTTP_FILTER_PREPROC_HEADERS *)pvData;
      BOOL bHeader = p->GetHeader(pfc,"User-Agent:",buffer,&buffSize); 
      CString UserAgent(buffer);
      if(UserAgent.GetLength() == 0) { // reject blank user agents
        p->SetHeader(pfc, "url", "/rejected-blank-user-agent");
      }
      return SF_STATUS_REQ_HANDLED_NOTIFICATION; 
    }
    return SF_STATUS_REQ_NEXT_NOTIFICATION; 
}
like image 110
Luke Peterson Avatar answered Oct 13 '22 06:10

Luke Peterson