WordPress – get post id where slug is LIKE something from specific category

Here is a custom WordPress function I came up with. It really isn’t that complicated, but it took me quite some time to figure out how to make it compatible with WordPress 3.5 and escape everything properly, since I’m not a WP developer. It returns ID of the post which is in the specified $cat_id category and it’s slug begins with $post_name. I hope somebody will find it useful :)

function get_post_like_slug($post_name, $cat_id) {
	global $wpdb;
	$post_name = $post_name;
        $id = $wpdb->get_var( $wpdb->prepare("SELECT ID FROM $wpdb->posts
        LEFT JOIN $wpdb->term_relationships ON $wpdb->posts.ID = $wpdb->term_relationships.object_id
        WHERE post_name LIKE %s AND $wpdb->term_relationships.term_taxonomy_id=%d LIMIT 1", $post_name.'%%', $cat_id ));

	if ( $id )
		return ($id);
	return null;
}

How to capitalize the first letter of all words in a file?

This is a handy Python one liner which will capitalize all words in a file. Module sys is used to handle stdin and stdout and built-in title() function will convert a line into a nice, correctly capitalized sentence.

python -c "import sys;[sys.stdout.write(line.title()) for line in sys.stdin]"

Some UNIX usage examples:

python -c "import sys;[sys.stdout.write(line.title()) for line in sys.stdin]" < file.txt
cat 'file.txt' | python -c "import sys;[sys.stdout.write(line.title()) for line in sys.stdin]"

Interesting Facebook glitch

Yesterday, I was randomly chatting on Facebook and out of nowhere, two icons appeared next to each message in my FB chat:

One icon looked like an arrow and the tooltip said “View message FBTrace” and the other one looked like a bug and said “Report a bug” – or similar.

When I clicked the trace icon, it took me to the following URL, but the page never loaded:

https://our.intern.facebook.com/intern/messages/fbtrace.php?message_id=id.*msg_id_num*

The icons were gone when I refreshed the page. I will probably never know what exactly happened, but I assume that this was a bug and I wasn’t ever supposed to see it, since it is an internal feature.

LinkedIn cracked passwords

This post is about the LinkedIn password hash leak that had occured on 5th of June. Original leakers published about 6,5 million SHA1 hashes on a Russian forum InsidePro.

Here is the original file that was published:
combo_not.zip ~118 MB

The file includes non-salted SHA1 hashes, with 3,5M of them “masked” with 5 leading zeros (more about this). You can use either a JTR patch or the special Hashcat version to crack them.

Here is a list of passwords I have cracked until now (3,6M) – format (hash:pass):
gesla.rar – cca. 92 MB

The list would be longer if I had more time and better hardware.

Google cache downloader in Python

I was searching for a script that would download an entire Google cache of a website automatically. I found this awesome Python script. It was a little outdated, but I ported it to Python 3.x and merged it with another version that had random time-outs between requests. But the script is far from complete, since Google blocks it after 50-150 requests, because it finds such behaviour “suspicious”. I created a Github repository for the script, so we can keep the script up to date and improve it with ease.

  • Download code & readme: gcache
#!/usr/bin/python
# Original script by: http://www.guyrutenberg.com/2008/10/02/retrieving-googles-cache-for-a-whole-website/
# Ported to Python 3.x by Luka Pušić <luka@pusic.si> http://360percents.com
#
import urllib.request
import re
import socket
import os
import random
import time
socket.setdefaulttimeout(30)
#adjust the site here
search_term="your search query here" #!!change this to your query!!
def main():
    headers = {'User-Agent': 'Mozilla/5.0 (X11; U; Linux i686 (x86_64); en-US; rv:1.8.1.4) Gecko/20070515 Firefox/2.0.0.4'}
    url = "http://www.google.com/search?q="+search_term
    regex_cache = re.compile(r'<a href="([^"]*)"[^>]*>Cached</a>')
    regex_next = re.compile('<a href="([^"]*)"[^>]*><span[^>]*>[^<]*</span><span[^>]*>Next</span></a>')
 
    #this is the directory we will save files to
    try:
        os.mkdir('files')
    except:
        pass
    counter = 0
    pagenum = 0
    more = True
    while(more):
        pagenum += 1
        print("PAGE"+str(pagenum)+": "+url)
        req = urllib.request.Request(url, None, headers)
        page = urllib.request.urlopen(req).read().decode("utf-8")
        matches = regex_cache.findall(page)
        for match in matches:
            match = 'http:'+match
            counter+=1
            tmp_req = urllib.request.Request(match.replace('&','&'), None, headers)
            tmp_page = urllib.request.urlopen(tmp_req).read()
            print(counter,": "+match)
            f = open('files/'+str(counter)+'.html','wb')
            f.write(tmp_page)
            f.close()
            #comment out the code below if you expect to crawl less than 50 pages
            random_interval=random.randrange(1,10,1)
            print("sleeping for: " + str(random_interval) + " seconds")
            time.sleep(random_interval)
        #now check if there is more pages
        match = regex_next.search(page)
        if match == None:
            more = False
        else:
            url = "http://www.google.com"+match.group(1).replace('&','&')
 
if __name__=="__main__":
    main()
 
# vim: ai ts=4 sts=4 et sw=4