Archive for the ‘ Computers ’ Category

Hardened Apache Mod_Rewrite Security Rules (Via yehg.net)

At work, we deal with hacked sites a lot. Most of them are from FTP-based attacks, which we can’t do much to stop. However, some are legit app vulnerabilities, which we can do more to stop. The below .htaccess rules help with ALL apps, but might require some tweaking.

# Hardened Apache Mod_Rewrite Security Rule
# Provided by Aung Khant,http://yehg.net
# Last Updated: 2011-02-24
# Note: You must experiment which strings make access denied in normal clean traffic. Remove such rules. Contact me if you can't.
# Ref: http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritecond # NC = 'nocase|NC' (no case-sensitive)
# OR = 'ornext|OR' (or next condition)
# L = last rule RewriteEngine on
# Allow only GET and POST verbs
RewriteEngine On
# 'Coz most vul scanners use HEAD for hunting buggy files existence
RewriteCond %{REQUEST_METHOD} !^(GET|POST)$ [NC,OR]
# Ban Typical Vulnerability Scanners and others
RewriteCond %{HTTP_USER_AGENT} ^.*(0d0a|sqlmap|ApacheBench|WhatWeb|ZeW|SlimBrowser|drone|DataCha|SBIder|Shelob|MobileRunner|Microsoft\sOffice|Plesk|Itah|Mosill|Internet\sExplorer\s4\.01|al_viewer|NetSeer|MSFrontPage|Yandex|webcollage|lwp\-trivial|Isidorus|core\-project|\|Toata\sdragostea\smea\spentru\sdiavola|StackRambler|Firebat|Y\!J\-SRD|lynx|Netsparker|Nstalker|ZmEu|libwww|perl|java|curl|ruby|python|nikto|wikto|pikto|pykto|scan|acunetix|qualys|fuck|kiss|ass|Morfeus|0wn|hack|h4x|h4x0r|w3af).* [NC,OR]
RewriteCond %{HTTP_USER_AGENT} ^.*(WWW\-Mechanize|revolt|wget|Crawl|Mail\.Ru|Walker|sbide|findlinks|spide|Ace\sExplorer|winhttp|HTTrack|clshttp|archiver|loader|email|harvest|extract|grab|miner).* [NC,OR] 

# Kick out Script Kiddies
RewriteCond %{HTTP_USER_AGENT} ^()$ [NC,OR]
# void of UserAgent 

# Disable access to cgi-bins if not used
RewriteCond %{REQUEST_URI} ^/(cgi\.cgi|webcgi|cgi\-914|cgi\-915|bin|cgi|mpcgi|cgi\-bin|ows\-bin|cgi\-sys|cgi\-local|htbin|cgibin|cgis|scripts|cgi\-win|fcgi\-bin|cgi\-exe|cgi\-home|cgi\-perl|scgi\-bin)/ [NC,OR] 

# Block out common attack strings
# Additional filtering can be put into
# HTTP_USER_AGENT, HTTP_REFERER, HTTP_COOKIE,HTTP_FORWARDED,HTTP_ACCEPT 

# Directory Travarsal, Null Byte Injection, HTTP Response Splitting
RewriteCond %{QUERY_STRING} ^.*(\.\./|\.\.%2f|\.\.%u2215|%u002e%u002e%u2215|%252e%252e%252f|%00|\\x00|\\u00|%5C00|%09|%0D%0A) [NC,OR] 

# SQL Injection Probing
RewriteCond %{QUERY_STRING} ^.*(\@\@version|CHR\(|CHAR\(|UNION%20SELECT|/select/|/union/|/insert/|/update/|/delete/).* [NC,OR]
RewriteCond %{QUERY_STRING} ^.*(or|and)%20([0-9]=[0-9]).* [NC,OR] 

#Remote/Local File Inclusion
# RFI: yoursite.com/?pg=http://evil.com/shell.txt?
# LFI: yoursite.com/?pg=/logs/access_log?
RewriteCond %{QUERY_STRING} .*(=https|=http|=ftp)(://|%3a%2f%2f).*\?$ [NC,OR]
RewriteCond %{QUERY_STRING} (passwd|boot\.ini|\/etc\/passwd|%2Fetc%2Fpasswd|c:\\boot\.ini|c%3A\\boot\.ini|c:\/boot\.ini|c:%2Fboot\.ini|c%3A%2Fboot\.ini|c:boot\.ini|c%3Aboot\.ini).* [NC,OR] 

# PHP Version Probing
RewriteCond %{QUERY_STRING} ^(=PHP).* [NC,OR] 

# XSS Probing RewriteCond %{QUERY_STRING} ^.*(\<|%3C).*script.*(\>|%3E) [NC,OR]
RewriteCond %{QUERY_STRING} ^.*(/XSS/).* [NC,OR] 

# PHP GLOBALS Overriding
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [NC,OR] 

# PHP REQUEST variable Overriding
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2}) [NC,OR] 

# PHP Command Injection Probing
# vuln.php?exec=uname -a;ls -al;whoami
RewriteCond %{QUERY_STRING} ^.*(=|;)(uname%20-|ls%20-|whoami).* 

# Deny access
RewriteRule ^(.*)$ / [R=404,F,L]

Node.js Fetch URL and display page body

Whoa, it’s been a long time since I’ve posted here. I’ve been working on a lot of fun stuff lately; SomaSeek.com is running an updated version using PHP-PDO and much-improved javascript. I’m also working on integrating Sphinx or Solr search (Sphinx is a bit more appealing to me but seems like it should have a generator that would analyse your DB schema and rough out a configuration for itself), and working on a JSON / SOAP / XML-RPC API for it (which I *might* just end up doing in Node.js for funsies).

Anyway, here is a quick diddy in Node.js that should help you get started a bit more than the super simple examples they usually provide. Pay close attention to the scope of everything and how the callbacks are working..it’s a bit to wrap your head around at first.

KNOWN LIMITATIONS (Want to fix it? Get on bitbucket and submit your patch!!! https://bitbucket.org/ip2k/simple-nodejs-fetch-and-display-page-body )

  • It will fail / barf if you request a page that redirects (like http://msn.com).  This is because msn.com redirects to www.msn.com and the HTTP status code is either 301 or 302.  Still working on better error trapping for that!
  • It won’t get secondary page resources.  Not sure how to solve that without involving sessions and/or forking, which is kind of beyond the scope of this right now.  I’m not going to implement this unless there is serious interest in this…not sure why there would be; you’d be better off using a proxy.
var request = require('request'),
  url = require('url'),
  http = require('http');

function getPage (someUri, callback) {
  request({uri: someUri}, function (error, response, body) {
      console.log("Fetched " +someUri+ " OK!");
      callback(body);
    });
}

var server = http.createServer(function (request, response) {
  requestedUri = url.parse(request.url).pathname;
  requestedUri = requestedUri.substring(1);
  console.log("Got request for " +requestedUri);
  if (!requestedUri.match('^http')) {
    console.log("requested URI is not a valid URL!  Dropping request...");
    response.writeHead(400, {"Content-Type": "text/html"})
    response.end("Invalid url");
  } else {
    getPage(requestedUri, function(body) {
      response.writeHead(200, {"Content-Type": "text/html"}),
      response.write(body),
      response.end("ip2k.com NodeJS simple server demo")
    })
  }
});

server.listen(8000);

console.log("Server running at http://127.0.0.1:8000/http://example.com");
console.log("To use, just append some URL as a request, like this: http://127.0.0.1:8000/http://example.com");

SomaSeek

somaseek.com is a new search engine for the history of all the great internet radio stations at http://somafm.com . It has near real-time history (updated every 5 minutes) and browsable history for each station. I’m working on getting pagination going for history, as well as a datepicker for browsing and Sphinx-powered search instead of the current MySQL fulltext search. I’m trying to keep it simple and not clutter it up with junk. I do plan on moving away from the very plain look of the site, but for now it’s usable and I’ve been tracking all of SomaFM’s stations since late February 2010, so there is already quite a bit of history that you can look through.

This project was born out of a few needs: I needed to get better at actual PHP / MySQL coding, I was annoyed with the twitter history of SomaFM (As of about a month ago, song history isn’t even listed on Twitter for the soma stations), and I always found good music through SomaFM but wanted to quickly learn more about the artist / song.

SomaFM has these key features to solve the above problems:
- Written in simple and extensible PHP / MySQL / JavaScript / CSS / HTML. Sphinx search coming soon.
- Tracks all of the stations, all of the time, so you can always search for what you were listening to.
- Provides links to LastFM, iLike, and Amazon Music (via SomaFM’s reseller link, so they get a portion of your purchase if you click through and buy via somaseek.com or somafm.com) to quickly find out more about songs / artists and give back to the community.
- Open source in actual implementation, just like Reddit. Other sites are starting to “see the light” and do this too. Hosted on Google Code is all the actual source code to the website, minus the database passwords, of course!
http://code.google.com/p/somaseek/

Please use and enjoy SomaSeek, and leave comments on this post if you have any ideas on how to improve it that weren’t listed above. I played with the idea of Facebook / Twitter “share” integration as well as trying to link to the groups on Facebook.

Spyware removal – Google search redirectors

I recently go some spyware through Google’s Chrome browser. I had disabled AVG 9 in hopes of getting Mass Effect to run longer than 30 minutes without crashing (to no avail).

Anyway, I was doing something on the internet somewhere and I saw the evil AntiVirus2009 window pop up and the icon in my system tray. I knew the next few hours would be packed with fun!

The key, I found, was to completely clear all of the cookies from all of my browsers (FireFox, Internet Explorer, MineField, Opera, Chrome, Chromium, and Iron). This fixed the link redirection issue.

Here are the free projects that let me eventually remove all the crap from Windows XP:
1.) Ultimate Boot CD. I loaded it and ran EZ PC Fix to clear my temp files and recycler. http://www.ubcd4win.com/index.htm
2.) Malware Bytes: http://www.malwarebytes.org/
3.) SpyBot SD: http://www.safer-networking.org/en/index.html
4.) AutoRuns: http://technet.microsoft.com/en-us/sysinternals/bb963902.aspx
5.) Hijack This: http://free.antivirus.com/hijackthis/
6.) LSPFix: http://www.cexx.org/lspfix.htm
7.) WinSockXP fix: http://www.snapfiles.com/get/winsockxpfix.html
8.) Fixwareout: Source unknown, can be found at http://ip2k.com/tools
9.) Dial-A-Fix: http://wiki.lunarsoft.net/wiki/Dial-a-fix
10.) Windows Installer CleanUp Utility (to remove broken MSI packages): http://support.microsoft.com/kb/290301

I have the hard-to-find stuff mirrored here ( http://ip2k.com/tools ) so it never gets lost

Update your Motrola Droid to Android 2.0.1

1.) Download the update file from http://ip2k.com/droid_2-0-1.zip
2.) rename the file “update.zip”
3.) Upload the zip file (do NOT extract it, leave it zipped!) to the root of your MicroSD card (not in any folders, just on the root of the card)
4.) You needed to pull the battery in your Droid to get the card out, so replace the card and open the keyboard.
5.) Hold the “x” key on the Droid’s keyboard and power it on. Continue holding “x” until you see a triangle with an exclamation point.
6.) Release the “x” key. Simultaneous press the “volume up” and “camera shutter” buttons. A menu should pop up.
7.) Using the D-Pad, select to update the system software from the update.zip file.
8.) The update will take a few minutes. During this time, do NOT pull the battery or attempt to turn off the phone. Doing so may corrupt the firmware on your device and render it unbootable.
9.) Once the update is complete, select “Reboot system now”. Enjoy!

This was written based on the original article at http://www.phonearena.com/htmls/Want-to-manually-update-your-Motorola-DROIDs-software-Heres-how.-article-comments-a_8232-p_2.html
md5sum of orig file (and my mirror): 3af35446905040a3123ec09195299596

Apple losing enterprise credability

Safari 4 has known issues with showing just a white screen randomly. There are many threads on the Apple support forums regarding this, here is an exmaple: http://discussions.apple.com/thread.jspa?messageID=9785751 . Personally, I use Google Chrome which is also a WebKit-based browser and I’ve never had an issue.

It seems that with the iPhone encryption issues ( http://www.broadbandreports.com/forum/r22999133-iPhone-31-breaks-Exchange-Sync-for-pre3GS-phones , and even on the new 3GS: http://arstechnica.com/apple/news/2009/07/new-iphone-hardware-encryption-not-even-close-to-hack-proof.ars ), the Snow Leopard data loss issues ( http://news.cnet.com/8301-31021_3-10373064-260.html ), and Time Capsules dying early ( http://gizmodo.com/5379865/are-apple-time-capsules-short-lived , http://timecapsuledead.org/ ) Apple doesn’t have it’s software development in line just quite yet.

With all these issues, it’s no surprise that at least a few people feel the same as this columnist: “I suspect that Apple has set back its enterprise cause several years, if not permanently.” ( http://www.itbusiness.ca/it/client/en/home/News.asp?id=54536&PageMem=2 )

Page 3 of 612345...Last »