So recently I started to study how botnets work. But recently I stumbled onto a problem. I even tried brain storming how it would do it, but I couldn't think how a bot would update its code. I also tried researching it on google, but I got nothing. If someone could provide me with some sort of software updating algorithm, or a documentation on how a bot would update then that then that would be nice.
Botnets reach out to a Command and Control (C2) server - typically a range of servers to help mitigate server takedown issues.
When they connect to a C2 server, the server may chose to initiate a function in the bot - for example to take part in a DDOS attack - or may chose to update code within the bot.
Clever bots will have the ability to rewrite themselves (or part of themselves) in memory as well as being able to update whatever file(s) the bot uses. Some bots only exist in memory and are lost on reboot.