/* * @version $Revision: 1.2 $ * @author Gary Ellison * @author Matt Curtin * @lyricist Doug Monroe * * you put your OPT-OUT in * you put your OPT-IN out * you put your OPT-OUT in * and you shake it all abOUT * * you do the CookiePokey * and your privacy is gone * that's what it's all about! * */ import java.io.*; import java.net.*; import java.util.*; public class CookiePokey { // a doubleclick cookie pusher which issues the redirect w/cookie static String defaultTarget = "http://ad.doubleclick.net/ad/www.doubleclick.net/optout;sz=1x1"; // where do you want to come from today static String defaultReferer = "http://www.doubleclick.net/"; // various user-agent strings static String ns6UserAgent = "Mozilla/5.0 (Windows; N; Win98; en-US; m14) Netscape6/6.0b1"; static String ns4UserAgent = "Mozilla/4.72 [en] (X11; U; SunOS 5.7 sun4u)"; static String operaUserAgent = "Opera/4.0 (Windows 98;US) Beta 3 [en]"; static String ieUserAgent = "Mozilla/4.0 (compatible; MSIE 5.01; Windows 98; c_athome)"; // that would be yes and no static String cookiePokeyAgent = "CookiePokey/4906 (Java; Interhack Corporation; Don't tread on me)"; static String oCookie = "id=OPT_OUT"; // lma static String pCookie = "id=A"; // prime-d-pump String referer; String cookieFieldKey; String userAgent; String target; String cookie; public CookiePokey(String url, String hdr, String cookie) { this.target = url; this.cookie = cookie; this.cookieFieldKey = hdr; // referer = defaultReferer; userAgent = cookiePokeyAgent; } public void setCookieFieldKey(String k) { cookieFieldKey = k; } public void setUA(String ua) { String userAgent = ua; } public void setReferer(String r) { String referer = r; } public String getCookie() { return cookie; } public void doThe() { try { URL url = new URL(target); URLConnection uc = url.openConnection(); HttpURLConnection http = null; if (uc instanceof HttpURLConnection) http = (HttpURLConnection) uc; else return; http.setRequestProperty("User-Agent", userAgent); http.setRequestProperty("Referer", referer); if (cookie != null && cookie.length() > 0) http.setRequestProperty(cookieFieldKey, cookie); // showem what j00 got System.out.println("\n_______"); System.out.println("Sending:"); System.out.println(" HTTP: GET " + target); System.out.println(" HTTP: User-Agent" + ": " + userAgent); System.out.println(" HTTP: Referer" + ": " + referer); if (cookie != null && cookie.length() > 0) System.out.println(" HTTP: " + cookieFieldKey + ": " + cookie); System.out.println(""); // and now for something completely different http.getInputStream(); System.out.println("Receiving:"); System.out.println(" HTTP: " + http.getHeaderField(0)); String key = null; for (int i=1; i < 10; i++) { if (http.getHeaderFieldKey(i) == null) break; key = http.getHeaderFieldKey(i); if (key.toLowerCase().startsWith("set-cookie")) { parseCookie(http.getHeaderField(i)); } System.out.println(" HTTP: " + key + ": " + http.getHeaderField(i)); } } catch (Exception e) { System.out.println("Ufda! " + e); e.printStackTrace(); } } void parseCookie(String c) { StringTokenizer st = new StringTokenizer(c, ";"); String token = null; while (st.hasMoreTokens()) { token = st.nextToken().trim(); if (token.startsWith("id=")) { cookie = token; break; } } } public static void main(String args[]) { String target = null; if (args.length < 1) { // you may also have to define proxy properties via // -Dhttp.proxyHost= -Dhttp.proxyPort= // System.out.println("usage warning: java CookiePokey " + defaultTarget); System.out.println("\tUsing default target " + defaultTarget); target = defaultTarget; } else { target = args[0]; } // redirects considered harmful HttpURLConnection.setFollowRedirects(false); // test priming CookiePokey cookiePokey = new CookiePokey(target, "Cookie", pCookie); cookiePokey.doThe(); // legal header keys Vector cookieHeaders = new Vector(); cookieHeaders.addElement("Cookie"); cookieHeaders.addElement("COOKIE"); cookieHeaders.addElement("cookie"); cookieHeaders.addElement("CoOkIe"); // now lets look for conformance Enumeration cooked = cookieHeaders.elements(); while (cooked.hasMoreElements()) { cookiePokey = new CookiePokey(target, (String)cooked.nextElement(), oCookie); cookiePokey.doThe(); } } }