Some malware remains after factory reset I have a MicroMax Canvas Doodle 4 Smart Phone with Android 5.0, purchased in November 2015.
It came with a lot of bloatware, probably including some app named "9Apps", which keeps suggesting apps for me to try out. I always cancel it.
While watching YouTube videos, I get some advertisements for some app or the other. Again I never click or install those.

Unfortunately, in touch-phones, it is possible to accidentally tap the wrong button and install malware unintentionally. Also, a friend installed CleanMaster to "help" me, but it looks suspicious to me.  

After about 6 months of usage, some malware got installed and it used to show random advertisements at odd times. It was tolerable for some time, but the frequency of advertisements increased, and there was a possibility that I might have unknowingly installed some more apps "suggested" by the malware.  

About 6 months back, anytime I would connect to wifi, "SystemUI" would automatically download a whole lot of apps : BatterySaver, Duplicate WhatsApp, web browsers, games, Pro*n downloaders, . . .
Also, Phone would become hot and battery would drain-out quickly. Crashes &amp; Reboots were common.  

I tried to uninstall all unknown apps, but either system would say that it could not disable system apps, or it would reinstall these apps at next wifi connect.

I tried a factory reset last week, but it was hanging on the next reboot. After repeating the factory reset, I got to the main screen, where I could see the Default Apps, but I got some popups like "WhatApps has stopped running" and "System update in Progress". Moreover, most of the unwanted apps are now shown as Default System Apps. Clearly, malware is still in control.  

How can I get rid of this malware ?
How can I reset the system to the real factory settings ?

I went to recovery mode and selected "root integrity check" : It shows 66 new files, 2 modified files, and 2 lost files. It does not provide a way to resolve these issues.
Other solution, more easy, is to root your device then :
1- block access to internet for these apps : install the firewall AFWall to block apps to access to internet. https://play.google.com/store/apps/details?id=dev.ukanth.ufirewall&amp;hl
2- install an ad blocker : https://f-droid.org/repository/browse/?fdid=org.adaway&amp;fdpage=2