How to fix "Socket creation in UltraProbe...Permission denied" error when using nmap?


Question

I have a pre-compiled nmap binary for Android that was working properly and without error in LineageOS 14.1. The phone is a One Plus One.



Since upgrading to Lineage 15.1 (Android 8), the specific error I get is:



Socket creation in UltraProbe* sendConnectScanProbe(UltraScanInfo, HostScanStats, u16, u8, u8): Permission denied (13).


This is when nmap is run as the standard user, as root the phone becomes unresponsive and immediately crashes. I read somewhere over on SO that someone who was also attempting to open a socket was running into a permission issue as well, but successfully circumvented it by adding the user into these groups: aid_bt, aid_bt_net, aid_inet, aid_net_raw, aid_admin



It doesn't seem like this version of LineageOS has either groupadd or usermod, so that solution doesn't help me.



Did any changes occur between the two versions of Lineage that could cause this problem?

And how can I make nmap work again?


Answer


Did any changes occur between the two versions of Lineage that could cause this problem



I don't have any experience with nmap and can't be sure why it worked with Android N, but Android has always been restrictive when it comes to socket access. I have been facing same issues at least from Marshmallow and onwards. ping is the common example.



It doesn't seem like this version of LineageOS has either groupadd or usermod



Android's users and permissions management is quite different than Linux. Bionic libc doesn't support many sycalls provided by standard glibc, particularly related to NSS. Also, the related files /etc/passwd, /etc/group, /etc/shadow and others don't exist on Android the way they exist on Linux. So, the standard Linux utilities groupadd and useradd etc. cannot be used on Android unless the source is modified and environment is modified accordingly.



how can I make nmap work again?



If you want to use a program compiled for standard Linux which needs capabilities CAP_NET_BIND_SERVICE, CAP_NET_ADMIN, CAP_NET_RAW etc., the program needs to be run by a user who is member of Android groups aid_inet, aid_admin and aid_net_raw. Even though the root user has apparently CAP_NET_* capabilities, socket syscall fails if it is not added to these groups explicitly. Most of the times only aid_inet suffices.


For instance, let's view capabilities of wpa_supplicant (process responsible for making wi-fi connections) on Android:


~$ su -c "getpcaps $(pidof wpa_supplicant)"
Capabilities for `21224': = cap_net_admin,cap_net_raw+ep

So, nmap won't work unless executed with its required capabilities. A capability is a subset of root permissions.


Terminal apps are usually already member of aid_net group (android.permission.INTERNET). However if it's not the case or you want to create a Linux type user on Android, follow on.


ADD LINUX USER ON ANDROID


NOTE: Device must be rooted.


On Linux, capabilities are assigned to a user (a user is a process id in fact, usually a shell) by some login mechanism, PAM modules being the most common. But there is no user login on Android, so we need to replicate that somehow. Lets create a Linux user, say "irfan" on Android.


Better is to use the UID of terminal app assigned at the time of app installation or you can use any unused UID like 6000.


Modify or create the files as below:


# /etc/passwd
irfan:x:10129:10129::/sdcard:/system/bin/sh
root:x:0:0::/data/local/tmp:/system/bin/sh

# /etc/group
aid_inet:x:3003:irfan,root

To login as user "irfan" with aid_inet as secondary group, use a Linux aware busybox su binary which regards /etc/passwd and /etc/group:


~$ id
uid=10129(u0_a129) gid=10129(u0_a129) groups=10129(u0_a129),9997(everybody)

~$ su -c 'busybox su - irfan'

~$ busybox id
uid=10129(irfan) gid=10129(irfan) groups=10129(irfan),3003(aid_inet)

Please note the usage of su twice. First su is the one you get when you root your device. It's because su must be executed with CAP_SETUID capability. But normal Android apps run without any capability:


~$ capsh --print | grep Bounding
Bounding set =

The first su grants us that capability (and all other capabilities) as well as avoids the need to setuid on busybox su binary.


In the same way you can add yourself to as many groups as you want, everybody, sdcard_rw and so on.


SOURCE:



Topics


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes