Skip to content

harshbpathak/Netsecure-android

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ›‘οΈ NetSecure

NetSecure is an Android network security and privacy monitoring app that captures real-time traffic via a local VPN, classifies it by app and category, performs Deep Packet Inspection with nDPI, runs a local Intrusion Detection System, and submits suspicious observables to an IntelOwl threat intelligence backend β€” all without root access.


Table of Contents


✨ Features

Traffic Capture & Analysis

  • Real-Time Packet Capture β€” Intercepts all TCP/UDP traffic through a high-performance local VPN tunnel powered by a native C engine with zdtun and libpcap.
  • Deep Packet Inspection β€” nDPI identifies 300+ application-layer protocols (TLS.Facebook, QUIC.YouTube, etc.) for accurate traffic classification.
  • Per-App Traffic Breakdown β€” Resolves every connection to the originating app via UID mapping, showing per-app request counts, data in/out, and connection details.
  • Traffic Categorization β€” Automatically classifies all connections into 10 categories: Social Media, Streaming, Ads & Trackers, Cloud, Messaging, Gaming, Shopping, System, CDN, and Other β€” using a three-stage pipeline (nDPI protocol β†’ domain suffix β†’ IP heuristics) with 300+ classification rules.
  • Connection Details β€” Every connection logs source/destination IPs and ports, L7 protocol, SNI/domain, bytes transferred, duration, encryption status, and timestamps.
  • CSV Export β€” Export all captured connections to a CSV file in your Downloads folder.

Threat Intelligence

  • IntelOwl Integration β€” Automatically submits suspicious IPs and domains to a self-hosted IntelOwl instance for analysis using configurable analyzers (AbuseIPDB, OTX, GreyNoise, MalwareBazaar).
  • Weighted Threat Scoring β€” Aggregates results from multiple analyzers with weighted scoring (AbuseIPDB 40%, OTX 30%, MalwareBazaar 20%, GreyNoise 10%) and classifies severity as Clean, Low, Medium, High, or Critical.
  • Priority Scan Queue β€” Intelligent queueing system that prioritizes blacklisted IPs, unknown protocols, and non-standard ports while skipping private IPs and known-safe endpoints.
  • Threat Alerts β€” Real-time dismissible alert banners for HIGH and CRITICAL findings on the dashboard.

Local Intrusion Detection

  • Signature-Based IDS β€” Scans unencrypted payloads against 11 regex-based signatures covering: cryptominer user-agents, IRC botnet commands, shell download chains, cleartext password exposure, SQL injection attempts, DNS queries to mining pools, malware C2 domains, DGA domains, Tor/onion routing, and phishing domains.

Privacy & Reporting

  • Privacy Report β€” Automated privacy concern detection: high tracker activity, excessive data transfer, suspicious request rates, and tracker domain exposure.
  • Top Talkers β€” Identifies the top 5 apps by data volume.
  • Threat Intelligence History β€” Searchable, filterable table of all scanned observables with severity breakdown, per-analyzer results, and score visualizations.

System

  • Persistent Logging β€” Dual-output logger (in-memory ring buffer + 1 MB rotating log file) with 5 levels and 4 tag categories, shareable via Android share sheet.
  • No Root Required β€” Uses Android's VPN Service API with split routing for transparent packet capture.
  • Dark Cybersecurity Theme β€” Navy/cyan/purple Material 3 dark theme designed for security monitoring.

πŸ“± Screens

Screen Description
Dashboard Summary cards (apps, requests, data in/out), category breakdown bar graph, per-app traffic cards with threat severity indicators, start/stop FAB, CSV export
App Detail Per-app deep dive with connection list (up to 300), L7 protocol chips, expandable connection details, per-connection IntelOwl threat reports
Report Privacy report with overall summary, data category breakdown, auto-generated privacy concern alerts, top talkers, threat intel summary
Threat Intelligence Full threat history with severity distribution chart, searchable observable table, per-analyzer result expansion (AbuseIPDB, OTX, GreyNoise, MalwareBazaar)
IntelOwl Settings Server URL, encrypted API token, TLP level selection, analyzer picker, cache TTL and concurrency sliders, connection test
Logs Live auto-scrolling log viewer with level/category/text filters, share/copy/save/clear actions

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚                    Jetpack Compose UI                    β”‚
β”‚  Dashboard Β· App Detail Β· Report Β· Threat Intel Β· Logs  β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚              ViewModels (StateFlow + MVVM)               β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚   TrafficRepository  β”‚      ThreatIntelRepository       β”‚
β”‚   TrafficClassifier  β”‚  ScanQueue Β· ThreatCache Β· IDS   β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”Όβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚  ConnectionsRegister β”‚     IntelOwl API (Retrofit)      β”‚
β”‚   (Ring Buffer 8K)   β”‚   EncryptedSharedPreferences     β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”΄β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚              CaptureService (VPN Service)                β”‚
β”‚                    JNI Bridge                            β”‚
β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚                 Native C Engine                          β”‚
β”‚     pcapdroid core Β· zdtun Β· nDPI Β· libpcap             β”‚
β”‚  TUN fd β†’ Packet Loop β†’ DPI Classification β†’ Callbacks  β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

Data flow:

  1. CaptureService creates a TUN interface via VPN Service and passes the file descriptor to the native engine.
  2. The native C core (pcapdroid.c) runs a packet loop using zdtun for TCP/UDP routing and nDPI for protocol identification.
  3. Connection data flows back to Kotlin via JNI callbacks β†’ ConnectionsRegister (ring buffer) β†’ TrafficRepository (classification & aggregation) β†’ ViewModels β†’ Compose UI.
  4. In parallel, ThreatIntelRepository extracts observables from connections, queues them by priority, batch-submits to IntelOwl every 5s, and polls for results every 10s.
  5. The SignatureScanner runs locally on unencrypted payloads and injects findings into the threat alert pipeline.

πŸ”§ Tech Stack

Layer Technology Version
Language Kotlin (app) Β· C (native engine) β€”
UI Jetpack Compose + Material 3 BOM 2024.09.00
Navigation Jetpack Navigation Compose 2.8.9
Architecture MVVM (ViewModel + StateFlow + Repository) β€”
Networking Retrofit 2 + OkHttp 2.11.0 / 4.12.0
JSON Gson 2.11.0
Async Kotlin Coroutines 1.8.1
Security EncryptedSharedPreferences (AES-256-GCM) 1.1.0-alpha06
Native Engine PCAPdroid core via JNI NDK 28.2
DPI nDPI submodule
Tunneling zdtun submodule
Packet Capture libpcap submodule (1.10.6)
GeoIP MaxMind DB Reader Java submodule
Build Gradle (Kotlin DSL) Β· CMake 3.22.1 AGP 9.0.1
Min SDK Android 7.0 (API 24)
Target SDK API 36

πŸ“ Project Structure

app/src/main/
β”œβ”€β”€ java/com/example/netsecure/
β”‚   β”œβ”€β”€ NetSecureApp.kt                  # Application class β€” initializes logger & IntelOwl config
β”‚   β”œβ”€β”€ MainActivity.kt                  # Single-activity Compose host with bottom navigation
β”‚   β”œβ”€β”€ CaptureService.kt               # VPN foreground service + JNI bridge
β”‚   β”‚
β”‚   β”œβ”€β”€ navigation/
β”‚   β”‚   └── NavGraph.kt                 # 6 routes: Dashboard, AppDetail, Report, ThreatIntel, Settings, Logs
β”‚   β”‚
β”‚   β”œβ”€β”€ ui/
β”‚   β”‚   β”œβ”€β”€ screens/
β”‚   β”‚   β”‚   β”œβ”€β”€ DashboardScreen.kt       # Main dashboard with traffic overview
β”‚   β”‚   β”‚   β”œβ”€β”€ AppDetailScreen.kt       # Per-app connection inspector
β”‚   β”‚   β”‚   β”œβ”€β”€ ReportScreen.kt          # Privacy report & analysis
β”‚   β”‚   β”‚   β”œβ”€β”€ ThreatIntelligenceScreen.kt  # Threat intel history & search
β”‚   β”‚   β”‚   β”œβ”€β”€ IntelOwlSettingsScreen.kt    # IntelOwl configuration
β”‚   β”‚   β”‚   └── LogsScreen.kt           # Live system log viewer
β”‚   β”‚   β”œβ”€β”€ viewmodel/
β”‚   β”‚   β”‚   β”œβ”€β”€ DashboardViewModel.kt    # Traffic state, capture control, threat summary
β”‚   β”‚   β”‚   β”œβ”€β”€ AppDetailViewModel.kt    # Per-app connection filtering & threat lookup
β”‚   β”‚   β”‚   β”œβ”€β”€ ThreatIntelViewModel.kt  # Observable table, severity stats, remote job fetch
β”‚   β”‚   β”‚   └── LogsViewModel.kt         # Log polling, filtering, export
β”‚   β”‚   └── theme/                       # Dark cybersecurity theme (Color, Theme, Type)
β”‚   β”‚
β”‚   β”œβ”€β”€ data/
β”‚   β”‚   β”œβ”€β”€ TrafficRepository.kt         # Traffic aggregation & app classification
β”‚   β”‚   β”œβ”€β”€ TrafficClassifier.kt         # 3-stage classifier (nDPI β†’ domain β†’ IP heuristics)
β”‚   β”‚   β”œβ”€β”€ ConnectionsRegister.kt       # Thread-safe ring buffer (8192 slots)
β”‚   β”‚   β”œβ”€β”€ ThreatIntelRepository.kt     # IntelOwl orchestration & result scoring
β”‚   β”‚   β”œβ”€β”€ ScanQueue.kt                 # Priority-based scan queue (max 500)
β”‚   β”‚   β”œβ”€β”€ ThreatCache.kt              # LRU cache (2000 entries) with TTL
β”‚   β”‚   β”œβ”€β”€ SignatureScanner.kt          # Local IDS with 11 regex signatures
β”‚   β”‚   └── model/                       # AppTrafficInfo, TrafficCategory, ThreatReport, etc.
β”‚   β”‚
β”‚   β”œβ”€β”€ model/                           # JNI-bridged models
β”‚   β”‚   β”œβ”€β”€ ConnectionDescriptor.kt      # Per-connection state (IPs, ports, L7 proto, SNI, payload)
β”‚   β”‚   β”œβ”€β”€ ConnectionUpdate.kt          # Incremental connection updates from native
β”‚   β”‚   β”œβ”€β”€ CaptureStats.kt             # Global capture statistics
β”‚   β”‚   β”œβ”€β”€ PayloadChunk.kt             # Raw payload bytes with metadata
β”‚   β”‚   β”œβ”€β”€ BlacklistDescriptor.kt      # IP/domain blacklist entries
β”‚   β”‚   └── MatchList.kt                # Firewall/whitelist rules
β”‚   β”‚
β”‚   β”œβ”€β”€ network/
β”‚   β”‚   β”œβ”€β”€ IntelOwlApiService.kt        # Retrofit interface (6 endpoints)
β”‚   β”‚   β”œβ”€β”€ IntelOwlConfig.kt            # Encrypted config with AndroidKeyStore
β”‚   β”‚   └── model/AnalysisModels.kt      # API request/response models
β”‚   β”‚
β”‚   └── logging/
β”‚       └── NetSecureLogger.kt           # Dual-output logger (memory + file)
β”‚
β”œβ”€β”€ jni/
β”‚   β”œβ”€β”€ CMakeLists.txt                   # Builds libcapture.so, libndpi.so, libzdtun.so
β”‚   β”œβ”€β”€ core/                            # Packet processing loop, VPN/PCAP capture, nDPI integration
β”‚   β”œβ”€β”€ common/                          # JNI utilities, UID resolution
β”‚   β”œβ”€β”€ pcapd/                           # Root capture daemon (alternative mode)
β”‚   └── third_party/                     # libchash (hash table)
β”‚
└── res/                                 # Drawables, icons, strings, themes

submodules/
β”œβ”€β”€ nDPI/                                # Deep Packet Inspection library
β”œβ”€β”€ zdtun/                               # TCP/UDP tunnel library
β”œβ”€β”€ libpcap/                             # Packet capture library
└── MaxMind-DB-Reader-java/              # GeoIP database reader

πŸš€ Getting Started

Prerequisites

  • Android Studio Ladybug or newer
  • JDK 17+
  • Android SDK with API 36
  • Android NDK 28.2.13676358 (auto-downloaded by Gradle)
  • CMake 3.22.1+

Build & Run

  1. Clone with submodules:

    git clone --recurse-submodules https://github.com/harshbpathak/Netsecure-android.git

    If already cloned:

    git submodule update --init --recursive
  2. Open in Android Studio and sync Gradle.

  3. Run on a physical device (API 24+).

Note: VPN capture and native routing work best on a physical device. Emulators may have limited networking depending on the configuration.

Permissions

The app requests these permissions at install or runtime:

Permission Why
INTERNET IntelOwl API calls
ACCESS_NETWORK_STATE Detect connectivity changes
ACCESS_WIFI_STATE Wi-Fi state detection
FOREGROUND_SERVICE Keep VPN capture alive in background
POST_NOTIFICATIONS Show capture notification (Android 13+)
QUERY_ALL_PACKAGES Resolve connection UIDs to app names and icons

πŸ”Œ IntelOwl Integration Setup

NetSecure integrates with IntelOwl β€” an open-source threat intelligence platform β€” to analyze suspicious IPs and domains observed in your traffic.

Setup Steps

  1. Deploy an IntelOwl instance (see IntelOwl docs).
  2. In NetSecure, go to Dashboard β†’ βš™οΈ Settings.
  3. Enter your Server URL and API Token.
  4. Hit Test Connection to verify.
  5. Select your preferred TLP level and analyzers.
  6. Enable the IntelOwl toggle β€” scanning starts automatically during capture.

Supported Analyzers

Analyzer What it checks
AbuseIPDB IP reputation from crowd-sourced abuse reports
OTXQuery AlienVault OTX threat pulse data
GreyNoiseCommunity Internet-wide scan/noise classification
MalwareBazaar Known malware indicator matching

Results are scored with weighted aggregation and cached locally (configurable TTL) to minimize API calls.


βš™οΈ How It Works

Packet Capture Pipeline

Android Apps
     β”‚  (all TCP/UDP traffic)
     β–Ό
TUN Interface (VPN Service)
     β”‚
     β–Ό
Native C Engine (libcapture.so)
  β”œβ”€β”€ zdtun: Routes packets through tunnel
  β”œβ”€β”€ nDPI: Identifies application-layer protocol
  └── Blacklist matching: Flags known-bad IPs/domains
     β”‚
     β–Ό  (JNI callbacks)
ConnectionsRegister (ring buffer, 8192 slots)
     β”‚
     β–Ό
TrafficRepository
  β”œβ”€β”€ UID β†’ App resolution (PackageManager)
  β”œβ”€β”€ TrafficClassifier (300+ domain/protocol rules)
  └── Per-app aggregation
     β”‚
     β”œβ”€β”€β–Ά UI (Dashboard, App Detail, Report)
     β”‚
     └──▢ ThreatIntelRepository
           β”œβ”€β”€ ScanQueue (priority-based, max 500)
           β”œβ”€β”€ SignatureScanner (local IDS, 11 signatures)
           β”œβ”€β”€ IntelOwl API (batch submit every 5s)
           β”œβ”€β”€ Job Poller (check results every 10s)
           β”œβ”€β”€ Weighted scoring & severity classification
           └── Alert pipeline β†’ UI

Traffic Classification Pipeline

Each connection goes through three classification stages:

  1. nDPI Protocol β€” Protocol name matching (e.g., TLS.Facebook β†’ Social Media)
  2. Domain Suffix β€” 300+ domain rules covering all major services and tracker networks
  3. IP Heuristics β€” Private IPs and well-known ports (53, 123) mapped to System category

πŸ”’ Security & Privacy

  • Encrypted Token Storage β€” IntelOwl API token protected with AES-256-GCM via EncryptedSharedPreferences backed by Android KeyStore.
  • Local Processing β€” All packet capture and classification happens on-device. Only observables you explicitly enable are sent to IntelOwl.
  • VPN Self-Exclusion β€” The app excludes itself from capture to prevent routing loops.
  • Split Routing β€” Uses 0.0.0.0/1 + 128.0.0.0/1 routes instead of default route to preserve system connectivity.
  • Private IP Filtering β€” RFC 1918 and link-local addresses are automatically excluded from threat scanning.
  • Rate Limiting β€” Exponential backoff (5s β†’ 60s) on API throttling to respect server limits.
  • No Data Collection β€” NetSecure does not send any data to external servers other than your configured IntelOwl instance.

πŸ“„ License

This project is licensed under the GPL-3.0 License.


🀝 Contributing

Contributions, issues, and feature requests are welcome. Feel free to open an issue or submit a pull request.

About

Lightweight Network Flow Analyser

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors