|
| 1 | +# MobSF AI Sidecar |
| 2 | + |
| 3 | +This project adds an AI-powered chat assistant to the [Mobile Security Framework (MobSF)](https://github.com/MobSF/Mobile-Security-Framework-MobSF). It allows security analysts to ask questions about the analysis report generated by MobSF directly within the interface, leveraging OpenAI's model. |
| 4 | + |
| 5 | +## Features |
| 6 | + |
| 7 | +- **Seamless Integration**: Injects a specialized chat interface directly into MobSF reports using an Nginx reverse proxy. |
| 8 | +- **Context-Aware**: The AI assistant automatically retrieves the current analysis report (static analysis) and uses it as context to answer your questions. |
| 9 | +- **Interactive Q&A**: Ask about vulnerabilities, code snippets, remediation steps or general security concepts related to your app. |
| 10 | + |
| 11 | +## Architecture & How It Works |
| 12 | + |
| 13 | +The solution is composed of three Docker services working together: |
| 14 | + |
| 15 | +1. **MobSF (`mobsf`)**: The standard Mobile Security Framework application running on port 8000. |
| 16 | +2. **Sidecar (`chat`)**: A Python Flask application that runs on port 5000. |
| 17 | + - Serves the chat UI. |
| 18 | + - Integrates the user, the MobSF API and OpenAI API. |
| 19 | + - Fetches the report JSON from MobSF using the unique scan hash. |
| 20 | + - Sends the relevant parts of the report along with the user's query to the OpenAI API. |
| 21 | +3. **Gateway (`gateway`)**: An Nginx reverse proxy (listening on port 8080) that coordinates everything: |
| 22 | + - Proxies standard traffic to the MobSF container. |
| 23 | + - Routes `/chat/` and `/api/chat` requests to the Sidecar container. |
| 24 | + |
| 25 | +### Data Flow |
| 26 | +1. User uploads the Mobile App in MobSF. |
| 27 | +2. User opens the view report in MobSF when mobile app analysis completed. |
| 28 | +3. User clicks the Chat button. |
| 29 | +4. Browser opens a separate chat window. |
| 30 | +5. User can integract with this particular app report data. |
| 31 | +6. Sidecar fetches the report from MobSF API then sends prompt + report + question to OpenAI and returns answer. |
| 32 | + |
| 33 | +## Prerequisites |
| 34 | + |
| 35 | +- [Docker](https://docs.docker.com/get-docker/) and [Docker Compose](https://docs.docker.com/compose/install/) |
| 36 | +- An [OpenAI API Key](https://platform.openai.com/api-keys) |
| 37 | + |
| 38 | +## Setup & Run |
| 39 | + |
| 40 | +1. **Clone the repository:** |
| 41 | + ```bash |
| 42 | + git clone <repository-url> |
| 43 | + cd Mobsf_Side_Car |
| 44 | + ``` |
| 45 | + |
| 46 | +2. **Configure Environment:** |
| 47 | + Open `docker-compose-mobsfai.yml` and check the environment variables. |
| 48 | + |
| 49 | + You generally need to provide your OpenAI API Key. You can set it directly in the file (not recommended for committed code) or export it in your shell: |
| 50 | + ```bash |
| 51 | + export MOBSF_OPENAI_API_KEY="sk-..." |
| 52 | + ``` |
| 53 | + |
| 54 | + *Note: The `MOBSF_API_KEY` is currently hardcoded to `1234567890` in the docker-compose file for both the MobSF instance and the Sidecar to communicate. If you change it in one place, ensure you update it in both services. You can the API in MobSF GUI as well.* |
| 55 | + |
| 56 | +3. **Build and Start:** |
| 57 | + Run the following command to build the chat container and start the stack: |
| 58 | + ```bash |
| 59 | + docker-compose -f docker-compose-mobsfai.yml up --build |
| 60 | + ``` |
| 61 | + OR |
| 62 | + ```bash |
| 63 | + docker-compose -f docker-compose-mobsfai.yml up -d --build |
| 64 | + ``` |
| 65 | + OR |
| 66 | + ```bash |
| 67 | + docker-compose -f docker-compose-mobsfai.yml down -v |
| 68 | + ``` |
| 69 | + |
| 70 | + |
| 71 | +4. **Access the Application:** |
| 72 | + Open your browser and navigate to: |
| 73 | + **http://localhost:8080** |
| 74 | + |
| 75 | + *(Note: Do not use port 8000, as that bypasses the Nginx gateway and the chat button will not appear.)* |
| 76 | + |
| 77 | +## Usage |
| 78 | + |
| 79 | +1. Go to **http://localhost:8080**. |
| 80 | +2. Upload an Android (APK) or iOS (IPA) application for analysis. |
| 81 | +3. Wait for the scan to complete. |
| 82 | +4. Once the "Static Analysis" report loads, look for a **floating Chat button (💬)** in the bottom-right corner. |
| 83 | +5. Click the button to open the AI assistant. |
| 84 | +6. Ask questions like: |
| 85 | + - "Summarize the critical vulnerabilities." |
| 86 | + - "How do I fix the high-severity issues found in the manifest?" |
| 87 | + - "Explain the 'Application is debuggable' finding." |
| 88 | + |
| 89 | +## Troubleshooting |
| 90 | + |
| 91 | +- **Chat button not appearing?** |
| 92 | + - Ensure you are accessing via `http://localhost:8080` and not port 8000. |
| 93 | + - Check the browser console for any JavaScript errors. |
| 94 | + - Ensure the URL contains `/StaticAnalyzer/` or matches the pattern expected by the injected script. |
| 95 | +- **AI Error / OpenAI Issues?** |
| 96 | + - Check the logs of the chat container: `docker logs mobsf_chat`. |
| 97 | + - Verify your `OPENAI_API_KEY` is valid and has access to the model. |
| 98 | +- **MobSF Communication Errors?** |
| 99 | + - Ensure the `MOBSF_API_KEY` matches in both the `mobsf` and `chat` service definitions in `docker-compose-mobsfai.yml`. |
| 100 | + |
| 101 | +## AshishSecDev |
0 commit comments