[5.0+][ROOT][3.6.0] AFWall+ IPTables Firewall [28 AUG 2023]

Search This thread

KonkavJS

New member
Jul 14, 2019
3
1
I was googleing around, and found something. There is a string matching possibility in iptables. So I connected to my phone over ADB, and listed policy's with
Code:
iptables -L -n --line-numbers
. Found out, that there is an 'afwall-wifi-wan' chain with a bunch of 'owner UID match <number>' . So I added:
Code:
iptables -I afwall-wifi-wan 44 -m owner --uid-owner 1000 -m string --string "generate_204" --algo bm -j RETURN
iptables -I afwall-wifi-wan 45 -m owner --uid-owner 1000 -m string --string "generate204" --algo bm -j RETURN
iptables -I afwall-wifi-wan 46 -m owner --uid-owner 1000 -m string --string "clients3.google.com" --algo bm -j RETURN
This should made the UID 1000, specifically the System UI, to connect to the google server to get the HTTP Response 204 (I tried to make sure, that the connection would go through). The iptables added just fine, I could list it, but unfortunately, it didn't work. And I don't know why. I have no experience in Android development. If somebody more experienced stop by, could please shred some light on this?

And yes , I was surprised that I found out, that there is a tcpdump on (at least my) phone.

Somebody maybe some idea?
 
  • Like
Reactions: Ultramanoid

Iolaum

Member
Sep 2, 2015
48
17
Hello,

I am considering using AFWall+. However I do not like rooting my devices. I prefer to use adb since on userdebug builds you can get root access through adb. That way I can grant special permissions to apps that need it. For example android.permission.READ_LOGS to MatLog Libre. Is it possible to use AFWall the same way? Meaning to install AFWall, and then use adb to give AFWall permissions a user will normally not be able to give through the UI, and then have AFWall function normally?
 
Last edited:

markd89

Senior Member
Jul 26, 2007
129
26
Phone flaky on connecting LTE but works with AFWall+ disabled

Hi,

I donated a couple of months ago.. I just got a "new" phone - Oneplus 5, LineageOS 16 MicroG running on T-Mobile in the USA. I have VolTE and VoWifi enabled.
I'm using AFWall 3.1 and haven't reinstalled the unlock key yet.

Main issue/question: With AFWall+ running the data connection will eventually show no bars. If I turn off AFWall+ then I quickly get back to LTE or LTE+

The log doesn't seem to work reliably. i.e. Right now it's showing something blocked 8 hours ago. I do see "weird ****" under Linux Kernel (-11) with lots of blocked connections: sky300-1.mail.vip.gq1.yahoo.com , amazonaws and other things that don't resolve to names. Curiously, (-11) shows allowed for Wifi and Mobile Data even though things are getting blocked.

Any suggestions on any of this, but most importantly the LTE connection, please let me know.

Thanks!
Mark
 
Last edited:

NYLimited

Inactive Recognized Contributor
Jan 5, 2008
3,825
2,286
New Hampshire, USA
Main issue/question: With AFWall+ running the data connection will eventually show no bars. If I turn off AFWall+ then I quickly get back to LTE or LTE+

To be honest I'm not sure I could figure out how AFWall or IPtables would change the signal strength or the bars which are only an indication of signal strength. I realize this is not very helpful but it has me scratching my head.
 

voroxda

Senior Member
Jun 17, 2014
210
105
Xiaomi Mi 11
Hi,
may be someone is able to help me? Unfortunately I am a little bit lazy, and I not really want to learn the ip-tables based rule syntax.
Now to my little problem, Google maps is on my device a great battery drainer, so first of all I disabled not needed services and broadcast receiver, second I disabled (freeze) the whole app, but the lovely company Google enables the app automatically again. Now I use the last possibility: if maps not needed I deinstall it (only the settings remains), and if needed I installed again. All steps are fully automated by tasker and lasts less than 2 seconds. At least I have to grant internet access again to Google maps. Does a possibility exists to automate this (granting internet access to Google maps on wlan and mobile)?
May be a afwall rule or sending an intent to afwall and how is the syntax.
Any hint is very appreciated.

Best regards

Sent from my Galaxy S8+ using XDA Labs
 

markd89

Senior Member
Jul 26, 2007
129
26
To be honest I'm not sure I could figure out how AFWall or IPtables would change the signal strength or the bars which are only an indication of signal strength. I realize this is not very helpful but it has me scratching my head.

The signal eventually drops to nothing. I'm thinking that there's a system process which is trying to connect somewhere to know that it has a good data connection.

Any ideas very welcome! Even with LOS it seems like there's plenty of unnecessary traffic that can be blocked.

Thanks again,
Mark
 

zarere

Senior Member
May 26, 2016
358
136
Sofia
The signal eventually drops to nothing. I'm thinking that there's a system process which is trying to connect somewhere to know that it has a good data connection.

Any ideas very welcome! Even with LOS it seems like there's plenty of unnecessary traffic that can be blocked.

Thanks again,
Mark

If you know German you can use
https://www.kuketz-blog.de/shelter-big-brother-apps-isolieren-take-back-control-teil7/
I"m posting the last (thread 7) since it has all links to the previous 6 threads.
If you don't know German use google translator. (It shows great results from German to English.)
 
  • Like
Reactions: markd89

mocarela

Senior Member
Jul 16, 2012
57
14
Does a possibility exists to automate this (granting internet access to Google maps on wlan and mobile)?

Applies for rooted shell...
With cat /data/system/packages.list | grep com.application.name | awk 'BEGIN {FS=" "} {print $2}' you get the UUID of an application.
Then iptables -I afwall-wifi-wan 1 -m owner $UUID -j RETURN grants access on wifi.
You can limit the destination with additional parameters -d X.Y.W.Z before -j RETURN.
And use the script for your automation process also in AFWall+.
 
Last edited:

voroxda

Senior Member
Jun 17, 2014
210
105
Xiaomi Mi 11
Applies for rooted shell...
With cat /data/system/packages.list | grep com.application.name | awk 'BEGIN {FS=" "} {print $2}' you get the UUID of an application.
Then iptables -I afwall-wifi-wan 1 -m owner $UUID -j RETURN grants access on wifi.
You can limit the destination with additional parameters -d X.Y.W.Z before -j RETURN.
And use the script for your automation process also in AFWall+.


Great thanks to mocarela :good:

That is for me the beginning to step into the iptables works. The statement to find out Uuid for Google maps works perfect. To grant internet access I have to adapt the chain itself and a little bit the syntax:

iptables -I afwall -m owner --uid-owner $UUID -j RETURN || exit

It works, but Afwall+ does not see the change?? Do I have to start an afwall applying/import command? But this is not important. Now I am able to grant temporarily access to internet for a special app, and that's want I wanted.
Again great thanks to mocarela.

Sent from my Galaxy S8+ using XDA Labs
 

mocarela

Senior Member
Jul 16, 2012
57
14
It works, but Afwall+ does not see the change??

AFWall+ won't see any rules created with external tools, since it doesn't parse existing. It just applies its own.
Thus... use also custom scripts (applying the external script you actually use) with AFWall+, otherwise it will delete the one for Maps created by the external script on its first run afterwards.
 
  • Like
Reactions: voroxda

mocarela

Senior Member
Jul 16, 2012
57
14
Somebody maybe some idea?

One thing that is wrong in your command, but this is not the cause it does not work (because after all the first rule would suffice), is that dots are not used in network packets. For details google "iptables string dots". So, in your third command you should use -m string --hex-string "|08|clients3|06|google|03|com".

I think the problem here is that "internet check" in question does not work simply as that anymore. I was able to narrow down the rules to:

Code:
iptables -I afwall-wifi-wan -m owner --uid-owner 1000 -d 172.217.19.99 -p tcp --destination-port 80 -j RETURN
iptables -I afwall-wifi-wan -m owner --uid-owner 1000 -d 216.58.214.227 -p tcp --destination-port 80 -j RETURN

I said narrow down, because it might depend on the location and the moment of execution of the check. After a while "System" will check some other hosts or its hardcoded hostnames will change their IPs and it won't work anymore.

So, the only thing that constantly works for me is the following:

Code:
iptables -I afwall-wifi-wan -m owner --uid-owner 1000 -d 172.217.0.0/16 -p tcp --destination-port 80 -j RETURN
iptables -I afwall-wifi-wan -m owner --uid-owner 1000 -d 216.58.214.0/24 -p tcp --destination-port 80 -j RETURN

That's all I was able to do so far. :( Not much, but better than nothing.
 

mocarela

Senior Member
Jul 16, 2012
57
14
Problem again... I just realized that rules are not applied at boot without manually applying them. I even don't have any script in the folder selected (in my case /data/adb/service.d).
So, what else do I need to enable on Xiaomi Mi 9 SE with MIUI 10.2.2 Global in order to get rules applied on boot? JFTR, I haven't disabled boot completed receiver or anything similar.
 

n0j0e

Senior Member
Can someone light me up why so many apps sorted as one app?
 

Attachments

  • Screenshot_20190724-163256.jpg
    Screenshot_20190724-163256.jpg
    199.2 KB · Views: 290
Last edited:

zarere

Senior Member
May 26, 2016
358
136
Sofia
Excellent point/question. Any chains expert?

Maybe related to https://developer.android.com/guide/topics/manifest/manifest-element.html#uid

and https://developer.android.com/guide/components/fundamentals

It's possible to arrange for two apps to share the same Linux user ID, in which case they are able to access each other's files. To conserve system resources, apps with the same user ID can also arrange to run in the same Linux process and share the same VM. The apps must also be signed with the same certificate
 
Last edited:

TiTiB

Senior Member
Jun 19, 2015
926
743
Earth, for now
I still find it truly mind boggling, and extremely worrisome. I can't be bothered to count that list / monstrosity, but for reference here are the 11 ( which I think are already too many ) under 1000 in my system.
I am an *extreme* debloater—I recently totally locked up my Tab S5e by messing with Samsung Payment/kgclient and had to go back to stock and start all over again—my nic stands for Tweak it Til it Breaks, after all. I am also, at heart, a minimalist, and strive to rid my devices of *everything* that is, imo, non-essential.

Privacy intruding apps/ops are my first targets and am willing to suffer crashes/lockups to see how much I can disable/delete/deactivate, et al. Four of my favorite tools are 3C Toolbox Pro, MyAndroidTools, App Ops by Xingchen & Rikk, and, of course, AFWall+.
 

Top Liked Posts

  • 1
    What is needed to be enabled to use Android Auto in my car?
    I'm not sure what you're asking, but AFWall is meant to block traffic based on certain rules. Why would you want to use AFWall in order to enable AA? Are you rooted? Custom ROM? What's your environment? Are you currently able to use AA in your car?
    1
    I'm not sure what you're asking, but AFWall is meant to block traffic based on certain rules. Why would you want to use AFWall in order to enable AA? Are you rooted? Custom ROM? What's your environment? Are you currently able to use AA in your car?

    Perhaps they are having trouble using Android auto with the Firewall, e.g., maybe AFwall is blocking Android Auto.

    +1 to your question/suggestion about whether or not Android Auto works okay when AFwall is not enabled.
    1
    What is needed to be enabled to use Android Auto in my car?
    this sounds like you are using afwall in whitelist mode (blocks everything, and you select what gets access)?

    if you run it in the recommended blacklist mode (allows everything, and you select what gets blocked) you should not have this issue - assuming you don't of course block android auto or some crucial system app.
    1
    What is needed to be enabled to use Android Auto in my car?
    I had to enable traffic for a bunch of XIAOMI system "apps" (they bundle a bunch of apps together so that you don't disable them) that disabled network if they didn't phone home successfully after a couple of minutes. Never buying anything from that underhanded manufacturer EVER AGAIN.
  • 1
    What is needed to be enabled to use Android Auto in my car?
    I'm not sure what you're asking, but AFWall is meant to block traffic based on certain rules. Why would you want to use AFWall in order to enable AA? Are you rooted? Custom ROM? What's your environment? Are you currently able to use AA in your car?
    1
    I'm not sure what you're asking, but AFWall is meant to block traffic based on certain rules. Why would you want to use AFWall in order to enable AA? Are you rooted? Custom ROM? What's your environment? Are you currently able to use AA in your car?

    Perhaps they are having trouble using Android auto with the Firewall, e.g., maybe AFwall is blocking Android Auto.

    +1 to your question/suggestion about whether or not Android Auto works okay when AFwall is not enabled.
    1
    What is needed to be enabled to use Android Auto in my car?
    this sounds like you are using afwall in whitelist mode (blocks everything, and you select what gets access)?

    if you run it in the recommended blacklist mode (allows everything, and you select what gets blocked) you should not have this issue - assuming you don't of course block android auto or some crucial system app.
    1
    What is needed to be enabled to use Android Auto in my car?
    I had to enable traffic for a bunch of XIAOMI system "apps" (they bundle a bunch of apps together so that you don't disable them) that disabled network if they didn't phone home successfully after a couple of minutes. Never buying anything from that underhanded manufacturer EVER AGAIN.
  • 404
    Welcome to official support page for AFWall+

    Disclaimer - As Usual. I'll not take any responsible if something goes wrong when using AFWall+

    Introduction
    AFWall+ is an improved version of DroidWall(front-end application for the powerful iptables Linux firewall). It allows you to restrict which applications are permitted to access your data networks (2G/3G/4G/LTE and/or Wi-Fi and while in roaming).Since the original author of Droidwall
    discontinued the project, I decided to keep the app instead of Avast Firewall. I'll continue to add more features as I can.


    Features
    - Supports 5.x to 13.x
    - Import/Export Rules to external storage
    - Search Applications
    - Multiple Profiles with custom names
    - Tasker/Locale support
    - Select All/None/Invert/Clear applications with single click
    - Revamped Rules/Logs Viewer with copy/export to external storage
    - Ability to view the network interfaces
    - Highlight system applications with custom color
    - Notify on new installations
    - Ability to hide application icons( faster loading )
    - Use LockPattern for application protection.
    - Show/Hide application ID.
    - Roaming Control for 3G/Edge
    - VPN Control
    - LAN Control
    - Tether Control
    - IPV6 Control
    - Tor Control
    - Choose able languages
    - Choose able iptables/busybox binary
    - Supports MIPS/x86/ARM
    - DNS Hostname

    Changelog - See third Post
    Current Version - 3.6.0

    To get Unlocker without Google services - Please follow the instructions here

    AFWall+ BETA Program
    1) AFWall+ opt-in for beta program
    2) Install AFWall+ and If you have any issues, just send email from (Menu -> Firewall Rules - > Send error report)

    Source Code/Wiki/FAQ
    AFWall+ is an free & opensource application
    Github
    Log an issue
    Frequently Asked Questions
    Many Thanks to @CHEF-KOCH

    Translations
    Translations - Please help me with translations in your language.
    http://crowdin.net/project/afwall

    Thanks To/Credits
    - German translations by chef@xda & user_99@xda & Gronkdalonka@xda
    - French translations by GermainZ@xda & Looki75@xda
    - Russian translations by Kirhe@xda & YaroslavKa78
    - Spanish translations by spezzino@crowdin
    - Dutch translations by DutchWaG@crowdin
    - Japanese translation by nnnn@crowdin
    - Ukrainian translation by andriykopanytsia@crowdin
    - Slovenian translation by bunga bunga@crowdin
    - Chinese Simplified translation by tianchaoren@crowdin
    - Polish translations by tst,Piotr Kowalski@crowdin
    - Swedish translations by CreepyLinguist@crowdin
    - Greek Translations by mpqo@crowdin
    - Portuguese translations by lemor2008@xda
    - Chinese Traditional by shiuan@crowdin
    - Chinese Simplified by wuwufei,tianchaoren @ crowdin
    - Italian translations by benzo@crowdin
    - Romanian tranlations by mysterys3by-facebook@crowdin
    - Czech translations by Syk3s

    Cheers,
    ukanth

    XDA:DevDB Information
    AFWall+ [ IPTables Firewall ], App for the Android General

    Contributors
    ukanth
    Source Code: https://github.com/ukanth/afwall


    Version Information
    Status:
    Stable
    Current Stable Version: 3.5.3
    Stable Release Date: 2022-06-28
    Current Beta Version:
    3.5.3
    Beta Release Date: 2022-06-28

    Created 2013-12-03
    Last Updated 2020-09-05
    70
    Version 3.0.1

    * Fix: Status toggle widget 1x1
    * Fix: Ability to hide ongoing notification (Stop firewall and restart to hide after disable it in preferences)
    * Fix: Firewall error notification on oreo and above
    * Security: Tile toggle checks for password
    * User reported crashes
    * Updated translations

    Previous version 3.0.0

    Features:
    * Better support for nougat/oreo and pie.
    * Firewall toggle tile
    * Adaptive Icons
    * Notification channels
    * Tor support

    Bugs:
    * General bug fixes and crash reports.
    * Language selection bug
    * Filter selection bug
    * Compatible with magisk 17.x
    * Better handling of background process
    * Drops support for 4.x devices
    * Update languages
    * Updated libraries

    Complete Changelog

    41
    Hello All,

    After careful analysis and testing, I decided not to rewrite the way rules are being applied due to lot of under hood changes required. Instead added few enhancements. Now applying rules from menu will show how many rules are getting applied with progress status. Also when adding/removing few rules , it will apply only those related rules instead of full apply.

    Also fixed couple of bugs and enhancements. You can get the full changelog from https://github.com/ukanth/afwall/blob/beta/Changelog.md

    This is BETA Version which is not released on playstore. I have been using this for past week and it's stable. But there might be bugs which I haven't encountered. Please test it and report it in case of any issues.

    Also I have been following XPrivacy thread on the decision by it's author. Just as FYI, I might fix it for my own usage when I update to nougat, I will share it here if anybody uses it here.

    BETA Link - https://www.dropbox.com/s/isvi413qyx6vb4d/AFWall+ 2.9.7-BETA-TESTER.apk?dl=0
    40
    Hello everyone,

    I have released 3.0.0 stable on playstore today. It's been a crazy month so far. After going through lot of dilemma of whether to support the existing afwall or write a new one from scratch, finally able to pull myself and release stable version of afwall with lots of bug fixes and new features along with pie support. Since I don't do full time Android development, it was hard to keep track of what's going on with sdk level changes.

    Thank you all for your support in AFWall+ development. Without your support it would simply not possible to pull through this.

    I will be out for couple of days ( taking off to spend time with my family ) and hopefully will be able to reply to questions once back.

    Thanks again and have a great day.
    35
    Hello everyone,

    I have released stable version of 3.1.0 to playstore and github. Its live on playstore. You can find the changelog along with md5/sha here

    https://github.com/ukanth/afwall/releases/tag/v3.1.0

    Thank you all for your continuous support in AFWall+ development.