File size: 1,442 Bytes
e12cd0f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash

echo 
echo '=======================MobSF Clean Script for Unix======================='
echo 'Running this script will delete the scan database, all files uploaded and generated.'

script_path=$(basename "$(dirname "$0")")
mobsf_home="$HOME/.MobSF"

# Ensure the script is run from the correct directory
if [[ "$script_path" != "scripts" ]]; then
    echo 'Please run this script from the MobSF directory:'
    echo './scripts/clean.sh'
    exit 1
fi

# Confirmation prompt
VAL=${1:-}
if [[ -z "$VAL" ]]; then
    read -p 'Continue? (Y/N): ' confirm
    [[ $confirm =~ ^[yY]([eE][sS])?$ ]] || exit 1
    VAL=$confirm
fi

echo
if [[ "$VAL" =~ ^[yY]$ ]]; then
    echo 'Cleaning up MobSF directories and files...'

    # Remove files from key directories
    rm -rf ./mobsf/{uploads,downloads,StaticAnalyzer/migrations,DynamicAnalyzer/migrations,MobSF/migrations}/*
    
    echo 'Removing Python bytecode and cache files'
    find ./ -type f -name "*.pyc" -o -name "*.pyo" -delete
    find ./ -type d -name "__pycache__" -exec rm -rf {} +

    # Remove temporary, log, and database files
    echo 'Deleting temporary, log, and database files'
    rm -f ./mobsf/debug.log ./classes* ./mobsf/db.sqlite3 ./mobsf/secret

    # Remove the MobSF data directory if it exists
    if [[ -d "$mobsf_home" ]]; then
        echo "Deleting MobSF data directory: $mobsf_home"
        rm -rf "$mobsf_home"
    fi

    echo 'Cleanup complete.'
fi