CookiesMonster loves Cookies
Java
225
White

Nobody viết ngày 10/03/2022

Hi,

Everyone knows that Web-Surfing is a nice time-killing fun. But fun without risk is never an exciting fun, isn't it? The more attractive sites you visit, the riskier your fun would be.

What risk you may ask, right? Well, it's the risk of spying cookies. Every Web Provider naturally wants to know who is currently viewing the page and where he was before he came here. Because of the Private Data Protection law the web providers are prohibited to extract and to stow the visitor's personal data.

IT is not IT if there weren't an alternative to circumvent the law. And the alternative is the cookie.

What is an IT Cookie? I am too lazy to explain cookie to you so I let Wikipedia explain it:

"HTTP cookies (also called web cookies, Internet cookies, browser cookies, or simply cookies) are small blocks of data created by a web server while a user is browsing a website and placed on the user's computer or other device by the user's web browser. Cookies are placed on the device used to access a website, and more than one cookie may be placed on a user's device during a session.

Cookies serve useful and sometimes essential functions on the web. They enable web servers to store stateful information (such as items added in the shopping cart in an online store) on the user's device or to track the user's browsing activity (including clicking particular buttons, logging in, or recording which pages were visited in the past). They can also be used to save for subsequent use information that the user previously entered into form fields, such as names, addresses, passwords, and payment card numbers."

(Source:WIKI)

alt text

Aha! Cookie is a small block of data and is "placed" on the user's computer. Further, Cookie enables web servers to store stateful information... If you are familiar with Enterprise JavaBeans (or Jakarta Enterprise Beans) you know what STATEFUL means and effects. So, the "stateful" cookie won't reveals your name, nor your personal details (such as age, address, etc.) but its presence on your computer indicates when and where you were on the Web. And that is more than enough to conclude your "web behavior". Your web behavior is as precious as gold. It lets the web provider know about your taste, your shopping habit and even your social movement.

How? Simple. When you, for example, visit Amazon, then eBay, then facebook and finally your favorite site (music, forum, etc.) the providers, which provide goods (Amazon or eBay) or advertise (facebook or your favorite site), implant a specific cookie into your computer (when a cookie does not exist) or read the cookie on your computer. Whatever they do they always know where the cookie originates: Amazon, eBay, facebook, etc. Enough to draw an image about your surfing behavior.

To minimize the risk and to confuse the spying-thirsty providers I show you a little app in Java SWING that allows you to "clean up" the cookies whenever you want or let it clean up periodically with a defined time interval. This app is written on WINDOWS 10. If your computer runs with other OS (UBUNTU or any other LINUX) you should explore into the HOME directory and check for the subdirectories where your browsers stow the cookies. The app is named CookiesMonster and requires an input text file CookiesList.txt as following:

#-------------------------------------------------------------------------------
# WINDOWS 10. On LINUX you have to check for the subdirectories in the
# HOME directory.
COOKIES_0=/AppData/Roaming/Opera Software/Opera Stable/cookies
COOKIES_1=/AppData/Roaming/Opera Software/Opera Stable/cookies-journal
COOKIES_2=/AppData/Local/Google/Chrome/User Data/Default/cookies
COOKIES_3=/AppData/Local/Google/Chrome/User Data/Default/cookies-journal
COOKIES_4=/AppData/Local/Google/Chrome/User Data/Default/Safe Browsing cookies
COOKIES_5=/AppData/Local/Google/Chrome/User Data/Default/Safe Browsing cookies-journal
COOKIES_6=/AppData/Local/Microsoft/Edge/User Data/Default/cookies
COOKIES_7=/AppData/Roaming/Mozilla/Firefox/Profiles/usqz5p89.default/cookies.sqlite
#
OPERA=/AppData/Roaming/Opera Software/Opera Stable
CHROME=/AppData/Local/Google/Chrome/User Data/Default
EDGE=/AppData/Local/Microsoft/Edge/User Data/Default
FIREFOX=/AppData/Roaming/Mozilla/Firefox/Profiles/usqz5p89.default
#
SWEEP=1000
POOL_SIZE = 100
#-------------------------------------------------------------------------------

alt text

import java.util.concurrent.*;
import java.nio.file.*;
import java.util.*;
import java.io.*;
//
import javax.swing.*;
// Joe T. Nartca (C)
public class CookiesMonster extends Thread {
  // Constructor
  public CookiesMonster(String file) throws Exception {
    // load the confi file for existed browsers
    // and "sweeping" time
    FileInputStream fin = new FileInputStream(file);
    prop = new Properties();
    prop.load(fin);
    fin.close();
    // Cookies sweeping time (milliSeconds)
    String cookies = prop.getProperty("SWEEP");
    if (cookies != null) {
      time = Integer.parseInt(cookies);
      if (time < 200) time = 200;
    }
    fLst = new ArrayList<>();
    for (int i = 0; ; ++i) {
      cookies = prop.getProperty("COOKIES_"+i);
      if (cookies == null) break;
      fLst.add((home+cookies).replace("/", File.separator));
    }
    start( );
  }
  @SuppressWarnings("unchecked")
  public void run( ) {
    // set FixedThreadPool
    pool = Executors.newFixedThreadPool(Integer.parseInt(prop.getProperty("POOL_SIZE")));
    for (final String fN : fLst) pool.submit(()-> {
      // check for Cookie entry by listening to the WatchKey
      // if a cookie is created or modified StandardWatchEventKind becomes true
      // if StandardWatchEventKind is true then the length of CookiesFile is set to 0 (or clear the content)
      // then take a "sweeping time" pause before next sweeping action restarts
      RandomAccessFile raf = null;
      try {
        raf = new RandomAccessFile(fN, "rw");
        int p = fN.lastIndexOf(File.separator);
        WatchKey wk = Paths.get(fN.substring(0, p)).register(FileSystems.getDefault().newWatchService(),
                                StandardWatchEventKinds.ENTRY_CREATE, StandardWatchEventKinds.ENTRY_MODIFY);
        String fil = fN.substring(p+1);
        OUT: while (!end) {
          for (WatchEvent<?> event : wk.pollEvents()) {
            WatchEvent.Kind<?> kind = event.kind();
            if (((WatchEvent<Path>)event).context().toString().equalsIgnoreCase(fil) &&
                (kind == StandardWatchEventKinds.ENTRY_MODIFY ||  kind == StandardWatchEventKinds.ENTRY_CREATE)) {
              if (raf.length() > 0) try {
                raf.setLength(0); // reset cookies
                break;
              } catch (Exception ex) { }
            }
            if (end) break OUT;
          }
          if (end) break;
          wk.reset();          
          try { Thread.sleep(time); }
          catch (Exception e) { }
        }        
      } catch (Exception ex) {
        ex.printStackTrace();
      }
      try { 
        if (raf != null) raf.close();
      } catch (Exception ex) { }
    });
  }
  //
  public void halt( ) {
    end = true;
    cleanNow( );
    if (pool != null) pool.shutdownNow();
    System.exit(0);
  }
  public void cleanNow( ) {
    // force to clean up all cookies of the listed browsers
    if (prop != null) try {
      String cookies;
      Thread.sleep(time);
      if (fLst != null) for (String file:fLst) {
        RandomAccessFile raf = new RandomAccessFile(file, "rw");
        raf.setLength(0);
        raf.close();
      }
      cookies = prop.getProperty("OPERA");
      if (cookies != null) { // Opera
        FileOutputStream fou = new FileOutputStream((home+cookies+"/opera_autoupdate.log").replace("/", File.separator), false);
        fou.close();
        File[] files = new File(cookies).listFiles();
        for (File file : files) if (file.isFile()) {
          String fn = file.getName(); // remove all ssdfp... files
          if (fn.indexOf("ssd") == 0 && fn.indexOf(".lock") < 0 || fn.indexOf(".old") > 0) file.delete();
        }
      }
      cookies = prop.getProperty("CHROME");
      if (cookies != null) { // Chrome
        File[] files = new File((home+cookies).replace("/", File.separator)).listFiles();
        for (File file : files) if (file.isFile() && file.getName().indexOf(".old") > 0 ) file.delete();
      }
      cookies = prop.getProperty("FIREFOX");
      if (cookies != null) {
        File[] files = new File((home+cookies).replace("/", File.separator)).listFiles();
        for (File file : files) if (file.isFile() && file.getName().indexOf(".bak") > 0 ) file.delete();
      }
    } catch (Exception ex) { }
  }
  //
  private int time = 500;
  private Properties prop;
  private List<String> fLst;
  private ExecutorService pool;
  private static CookiesMonster zombie;
  private volatile boolean end = false;
  private String home = System.getProperty("user.home");
  //----------------------------------------------------------------------------------------------------
  public static void main(String... argv) throws Exception {
    UIManager.setLookAndFeel("com.sun.java.swing.plaf.nimbus.NimbusLookAndFeel");
    JFrame jf = new JFrame("CookiesMonster");
    jf.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    JLabel msg = new JLabel("Enter CookiesList and press ENTER to start");
    JTextField conf = new JTextField(argv.length > 0? argv[0]:"CookiesList.txt");
    conf.addActionListener(e -> {
      if (zombie == null) try {
        zombie = new CookiesMonster(conf.getText());
        msg.setText("CookiesMonster is lurking...");
        conf.setEditable(false);
      } catch (Exception ex) {
        ex.printStackTrace();
        System.exit(0);
      }
    });
    JLabel labC = new JLabel("CookiesList file");
    JButton but = new JButton("CLEAN COOKIES NOW");
    but.addActionListener(e -> {
      if (zombie != null) {
        zombie.cleanNow();
        msg.setText("All cookies were swept away");
      }
    });
    JButton stop = new JButton("EXIT & CLEAN UP");
    stop.addActionListener(e -> {
      if (zombie != null) zombie.halt();
      else System.exit(0);
    });
    jf.addWindowListener(new java.awt.event.WindowAdapter() {
       public void windowClosing(java.awt.event.WindowEvent ew){
        if (zombie != null) zombie.halt();
        else System.exit(0);
       }
    });
    JPanel north = new JPanel();
    north.add(labC); north.add(conf);
    JPanel center = new JPanel();
    center.add(but); center.add(stop);
    JPanel south = new JPanel();
    south.add(msg);

    jf.add("North", north);
    jf.add("Center", center);
    jf.add("South", south);
    jf.pack();
    jf.setVisible(true);
  }
}

if you have successfully downloaded the codes and the list, modified the list and compiled them you get this screen
alt text

Good luck and enjoy.
More: click HERE

Bình luận


White
{{ comment.user.name }}
Bỏ hay Hay
{{comment.like_count}}
Male avatar
{{ comment_error }}
Hủy
   

Hiển thị thử

Chỉnh sửa

White

Nobody

20 bài viết.
557 người follow
Kipalog
{{userFollowed ? 'Following' : 'Follow'}}
Cùng một tác giả
White
1 2
Chao Cac Ban I was absent for a very long time... To my wonder that Kipalog is still alive. It's a very good news. Today I show you a brief tutor...
Nobody viết 5 tháng trước
1 2
White
1 0
(Ảnh) I found this question in a Vietnamese forum ((Link)). The questioner is certainly not a man who's studied Computer Science (or in Vietnamese...
Nobody viết 4 tháng trước
1 0
White
1 0
This tutorial is a summary of the two last tutorials 1. OCR: (Link) 2. JAVA: (Link) With the knowledge we have about the way how to process an Ima...
Nobody viết 3 tháng trước
1 0
Bài viết liên quan
White
2 0
Trong bài viết này, một số hình ảnh hoặc nọi dung có thể bị thiếu do quá trình chế bản. Vui lòng xem nội dung ở blog gốc sau: (Link) (Link), chúng...
programmerit viết hơn 6 năm trước
2 0
White
0 0
Giới thiệu Trong bài hôm nay chúng ta sẽ tìm hiểu cách handle request POST của Spring Boot. Trước đó, bạn nên biết 1. 「Spring Boot 8」Tạo Web He...
https://loda.me viết gần 3 năm trước
0 0
Male avatar
0 0
https://grokonez.com/deployment/vultr/howtoinstalljavainubunturemoteservervutrhostingvpsexample How to install Java on Ubuntu Remote Server – Vutr...
loveprogramming viết 1 năm trước
0 0
{{like_count}}

kipalog

{{ comment_count }}

bình luận

{{liked ? "Đã kipalog" : "Kipalog"}}


White
{{userFollowed ? 'Following' : 'Follow'}}
20 bài viết.
557 người follow

 Đầu mục bài viết

Vẫn còn nữa! x

Kipalog vẫn còn rất nhiều bài viết hay và chủ đề thú vị chờ bạn khám phá!