{"id":836,"date":"2014-10-25T09:00:21","date_gmt":"2014-10-25T08:00:21","guid":{"rendered":"http:\/\/www.floyd.ch\/?p=836"},"modified":"2014-10-08T12:30:21","modified_gmt":"2014-10-08T11:30:21","slug":"android-app-configuration-manipulation","status":"publish","type":"post","link":"https:\/\/www.floyd.ch\/?p=836","title":{"rendered":"Android app configuration manipulation"},"content":{"rendered":"<p>So you got an Android application and you would like to temper with its configuration files? Nothing easier than that as long as you have a rooted Android phone, a sqlite editor and a text editor.<\/p>\n<p>I only wanted to temper with the databases of the app. I used this script (pull-databases.sh) to get the databases:<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nAPP=com.example.theNameInYourAndroidManifest\r\nTMP=\/data\/local\/tmp\r\nAPP_UID=`adb shell dumpsys package $APP|grep userId=|cut -d &quot; &quot; -f 5|cut -d &quot;=&quot; -f 2`\r\n#after first run, maybe hardcode, so you can also push files when Android is still starting up and before the app started:\r\n#APP_UID=10000\r\necho &quot;&#x5B;+] Removing local folder&quot;\r\nrm -r .\/$APP-databases\r\necho &quot;&#x5B;+] The applications UID and GID is:&quot;\r\necho $APP_UID\r\necho &quot;&#x5B;+] Copying database to tmp dir&quot;\r\nadb shell &quot;su -c cp -r \/data\/data\/$APP\/databases $TMP\/$APP-databases&quot;\r\necho &quot;&#x5B;+] chmoding tmp dir to 777&quot;\r\nadb shell &quot;su -c chmod -R 777 $TMP\/$APP-databases&quot;\r\necho &quot;&#x5B;+] Pulling database&quot;\r\nadb pull $TMP\/$APP-databases $APP-databases\r\necho &quot;&#x5B;+] Removing database in tmp&quot;\r\nadb shell &quot;su -c rm -r $TMP\/$APP-databases&quot;\r\n<\/pre>\n<p>You might need to change the cut commands, as they might not work in every case. Then, to upload the databases back to the phone, use this script (push-databases.sh):<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nAPP=com.example.theNameInYourAndroidManifest\r\nTMP=\/data\/local\/tmp\r\nAPP_UID=`adb shell dumpsys package $APP|grep userId=|cut -d &quot; &quot; -f 5|cut -d &quot;=&quot; -f 2`\r\n#after first run, maybe hardcode, so you can also push files when Android is still starting up and before the app started:\r\n#APP_UID=10000\r\necho &quot;&#x5B;+] The applications UID and GID is:&quot;\r\necho $APP_UID\r\necho &quot;&#x5B;+] Pushing to tmp dir&quot;\r\nadb push $APP-databases $TMP\/$APP-databases\r\necho &quot;&#x5B;+] Copying from tmp to app dir&quot;\r\nadb shell &quot;su -c cp -pr $TMP\/$APP-databases\/* \/data\/data\/$APP\/databases\/&quot;\r\n#cp -p  doesn't seem to preserver mode, but sets it to 666\r\necho &quot;&#x5B;+] chmoding app dir&quot;\r\n#attention: 777, easy way out, but databases might have different flags...\r\nadb shell &quot;su -c chmod -R 777 \/data\/data\/$APP\/databases&quot;\r\nadb shell &quot;su -c chmod 771 \/data\/data\/$APP\/databases&quot;\r\necho &quot;&#x5B;+] removing tmp database&quot;\r\nadb shell &quot;su -c rm -r $TMP\/$APP-databases&quot;\r\n#cp -p doesn't seem to preserve owner, but sets it to shell\r\necho &quot;&#x5B;+] chowning app dir&quot;\r\nadb shell &quot;su -c chown $APP_UID.$APP_UID \/data\/data\/$APP\/databases&quot;\r\nadb shell &quot;su -c chown $APP_UID.$APP_UID \/data\/data\/$APP\/databases\/*&quot;\r\n<\/pre>\n<p>If you want to get the entire configuration of the app, you can use this script (pull-all.sh):<\/p>\n<pre class=\"brush: bash; title: ; notranslate\" title=\"\">\r\nAPP=com.example.theNameInYourAndroidManifest\r\nTMP=\/data\/local\/tmp\r\nAPP_UID=`adb shell dumpsys package $APP|grep userId=|cut -d &quot; &quot; -f 5|cut -d &quot;=&quot; -f 2`\r\n#after first run, maybe hardcode, so you can also push files when Android is still starting up and before the app started:\r\n#APP_UID=10000\r\necho &quot;&#x5B;+] Removing local folder&quot;\r\nrm -r .\/$APP\r\necho &quot;&#x5B;+] The applications UID and GID is:&quot;\r\necho $APP_UID\r\necho &quot;&#x5B;+] Copying app dir to tmp dir&quot;\r\nadb shell &quot;su -c cp -r \/data\/data\/$APP $TMP\/$APP&quot;\r\necho &quot;&#x5B;+] chmoding tmp dir to 777&quot;\r\nadb shell &quot;su -c chmod -R 777 $TMP\/$APP&quot;\r\necho &quot;&#x5B;+] Pulling app dir from tmp&quot;\r\nadb pull $TMP\/$APP $APP\r\necho &quot;&#x5B;+] Removing app dir in tmp&quot;\r\nadb shell &quot;su -c rm -r $TMP\/$APP&quot;\r\n<\/pre>\n<p>As I didn&#8217;t need to push the entire app configuration, I didn&#8217;t write a push-all.sh script. That could get messy with the permissions and I didn&#8217;t want to do a chmod 777. But of course you can do that if you like.<\/p>\n<p>These simple scripts got me some really nice results during pentests. Activate apps that I only had in the free version. Reset the app&#8217;s PIN lock count. Disable ads showing in the application.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>So you got an Android application and you would like to temper with its configuration files? Nothing easier than that as long as you have a rooted Android phone, a sqlite editor and a text editor. I only wanted to &hellip; <a href=\"https:\/\/www.floyd.ch\/?p=836\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,10,19],"tags":[158,45,141,35],"class_list":["post-836","post","type-post","status-publish","format-standard","hentry","category-android","category-mobile-security","category-useful-scripts","tag-android","tag-bash","tag-configuration-tempering","tag-cracking"],"_links":{"self":[{"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/posts\/836","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=836"}],"version-history":[{"count":4,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/posts\/836\/revisions"}],"predecessor-version":[{"id":840,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=\/wp\/v2\/posts\/836\/revisions\/840"}],"wp:attachment":[{"href":"https:\/\/www.floyd.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=836"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=836"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.floyd.ch\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=836"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}