Searching for Random

As I was "casually" surfing the web I stumbled upon some PHP files with random names. It turns out that these files are backdoors created by a hacking tool, which might warrant a post on its own later. The problem is that you can't really search for random data in a similar fashion as you can do with Google Dorks for specific files. So given a bunch of files, how would you find the ones with random names? In this post, I'll outline a statistical approach (#AI, #MachineLearning, #BigData, ...) I managed to use with some success to find multiple active and useable backdoors online. That being said, it's only a first step and far from perfect, any input on possible improvements is appreciated!

Motivating example

To shine some more light on what I mean, here is an example:
Which of these five files have a random name?

  • readertest.php
  • fkzptcdrrj.php
  • timeserver.php
  • datatables.php
  • fileserver.php

For anyone that knows English, this is pretty obvious, it's fkzptcdrrj.php.
While it's easy to tell in this case, how would you program a general solution for finding this file?

Specification

In the specific case of this malware, there are some things we know. The filename, excluding extension, is ten characters long and only lowercase letters. This is based on observations, I still haven't found the exact generating function for the names. 

Method

My first idea was to try some machine learning solution to detect English but I didn't like that solution. Firstly, it would fail for non-English names like "configuraracceso.php", "MotDePasse.php", etc. Secondly, it might also break for names with special characters like "edit_user.php", "wp-login.php", etc.

Since my wife is a librarian and a professional in data retrieval, I started by asking her. Understandably, she was a bit stumped at my request to find random names. However, before soon she recommended looking for names with "unlikely patterns".

Happily, I have created my own database with lots of file names that I use to uncover these unlikely patterns. The idea was to use this to create a Markov Chain with transition probabilities between characters in the names. Then finally, for each name, calculate the probability for the corresponding path in the chain. The names with the lowest probability are the "unlikely patterns".

To generate the Markov Chain I used approximately 16,000 unique file names of variable length converted to lowercase.

Example

If we have the files "abc", "aaa", and "aac" we construct the following chain. We start with "abc" where we have one "a b" transition and one "b c" transition, then "aaa" with two "a a" transition and finally "aac" with one "a a" and one "a c" transition. Now, for "a" there is a 1/5 chance the next character is "b", 3/5 it is "a" and a 1/5 that it is "c".

Results

Starting with the Markov Chain, the transitions seem to make sense. "f  i" is very popular at about 18% (any file name with "file" in the name will add to this), while "f  v" is very unlikely at 0.02%. Below is the Markov Chain for the likely name "fileserver".

Markov chain for the word

The top five most "likely" ten letter names results were:

  1. fileserver.php (8.2e-08)
  2. datatables.php (7.1e-08), 
  3. controller.php (7.0e-08),
  4. icontainer.php (1.9e-08),
  5. convention.php (1.8e-08).

And for the key results, the most "unlikely" names (slightly changed to preserve anonymity for victims):

  1. u5xvnsnvdn.php (1.42e-24)
  2. wp-dk1ugc4.php (4.3e-21)
  3. fkzptcdrrj.php (1.23e-20)
  4. wp-z0czikm.php (1.6e-19)
  5. wp-05qvpwb.php (2.4e-19)

I am very happy with these results! All top five results are from hacked servers. fkzptcdrrj.php was executable allowing for RCE. Actually, 1,2,4, and 5 are all from the same hacked server.

The seventh most unlikely pattern was an active web shell from the same malware authors that anyone could use on the infected server, as shown in the figure below.

Web shell with random name

Discussion

While I think these results were surprisingly good I'm sure there is much room for improvement. Even continuing on the Markov Chain model there are many parameters. Should everything be converted to lowercase? Should only unique names be used? If the target length is 10, should only names of this length be used?

Looking at more than the top 5 results, there are quite a lot of false positives (non-random names) like "logoff_wtd", "notify_vtm", "bookflight". The first two are combinations of words and other data. "bookflight" is interesting as it is a combination of two normal English words, but the "k  f" transition is quite rare (1%). Some names arguably seem random, like "esp8266h2o", unless you know that "ESP8266" is a microchip. So perhaps including some word lists or knowledge databases could help eliminate false positives.

Almost eveyone I've told about this to have mentioned ENTROPY! "Just calculate the entropy", "find the name with highest entropy", etc. But this is really not straight forward. Sometimes a simplified version is used for passwords where entropy can be calculated as E = L * log2(R), where L is the length and R the size of the character set. This doesn't really help us in deciding if "admin" or "fkzpt" has the highest entropy, as the have the same length and possible same character set [a-z]. I believe the core problem is that we need to know the distribution of file names before entropy can be applied. Please let me know if you have a good idea on this track! 

Conclusion

Markov chains are pretty good at finding probable patterns and consequently also non-patterns or randomness. Furthermore, multiple of the random files I found were indeed malicious with some even providing RCE on the infected servers.

 


Write your comment!

Comments

AM !8567b3b233e9 No. 1419 >>1421 2022-09-19 08:55:19
> This doesn't really help us in deciding if "admin" or "fkzpt" has the highest entropy.

Not if you consider letters separately, but you could split the word into n-grams (2- or 3- grams could be enough), and then compare by their entropy instead. "ad" should be a much more common 2-gram than "fk" in most popular languages.
Benjamin ## Admin !d2782292df32 No. 1421 2022-09-24 10:49:34
>>1419
Awesome idea AM! :)

For the total probability of a filename, I'm simply taking the product of each ngram in the filename divided by the total weighted ngrams in the dataset. This seems to work but maybe there is a more correct method to do it?

Looking at the bigrams the results are very similar with pretty much the same top lists for both common and uncommon. I guess this makes sense as bigrams and transition probabilities between individual characters are similar. The most common bigrams are "er" (423/13140) and "on" (284/13140). Indeed you are correct that "ad" (86/13140) is much more common than "fk" (1/13140), nice!

Trigrams also give similar results but perhaps a bit more false positives. For example, "subscriber" is the third most unlikely result. Most common trigrams are "ion", "con", and "tio", which makes sense too.

In practice, it would probably be useful to complement/filter the results w.r.t. to popular dictionaries.


yasu313 No. 1422 2022-10-19 20:26:09
good job bejamin :D
Hisssssssss There No. 4834 2024-02-05 16:04:05
Holle this is 6est
Sergcxl No. 9171 2025-09-27 09:23:51
Do you know what holiday it is today?
We are used to the fact that we know only religious and public holidays and celebrate only them.
I found out about this only yesterday after visiting the our site.
It turns out that every day there are from 2 to 10 different holidays that surround us and make our lives happier.
Here is one of the holidays that will be today:


http://epaqi.com/forum.php?mod=viewthread&tid=116034&pid=117798&page=5&extra=#pid117798
http://bbs.epaqi.com/forum.php?mod=viewthread&tid=116261&extra=
http://www.mutterkind-kur.de/forum/viewtopic.php?f=29&t=1092674
http://epaqi.com/forum.php?mod=viewthread&tid=115949&extra=
http://hd18.cn/bbs/viewthread.php?tid=182405&extra=
Sergldl No. 9173 2025-09-27 11:39:49
Do you know what holiday it is today?
We are used to the fact that we know only religious and public holidays and celebrate only them.
I found out about this only yesterday after visiting the our site.
It turns out that every day there are from 2 to 10 different holidays that surround us and make our lives happier.
Here is one of the holidays that will be today:


http://fionpoon81.ecec-shop.com/bbs/viewthread.php?tid=178759&extra=page%3D1
http://bbs.suseage.com/forum.php?mod=viewthread&tid=196752&extra=
http://bbs.epaqi.com/forum.php?mod=viewthread&tid=116152&pid=118075&page=3&extra=#pid118075
http://www.fabetghislain.free.fr/Pages/phpBB2/viewtopic.php?p=313#313
http://bimmer-toolset.com/forum/viewtopic.php?t=162
Veronayls No. 9175 2025-09-27 21:17:25
Советую Вам отличную пасеку, на которой заказываю большой ассортимент продукции как для себя таки для своих знакомых.
Пчеловоды оформляют всю пчелопродукцию на отменно, советы как принимать по важным вопросам дают. Очень много качественных статей на сайте, Вот несколько из них:
http://sedemo5.b-pay.net/?q=blog/social-logins-made-simple&page=341#comment-36551
http://www.c-strike.fakaheda.eu/forum/viewthread.php?thread_id=2182
http://fionpoon81.ecec-shop.com/bbs/viewthread.php?tid=179609&pid=340657&page=1&extra=page%3D1#pid340657
http://www.epaqi.com/forum.php?mod=viewthread&tid=116179&pid=118131&page=2&extra=#pid118131
http://boletinelbohio.com/user/veronaaio/?um_action=edit

Одним словом они молодцы и я их рекомендую.
Вот их портал где я заказывал иммуностимулирующие продукты.
Veronaxwo No. 9177 2025-09-27 23:25:34
Советую Вам хорошую пасеку, на которой покупаю большой ассортимент продукции как для себя таки для своих родственников.
Пчеловоды делают всю пчелопродукцию на пять, консультации по важным вопросам дают. Очень много качественных статей на блоге, Вот несколько из них:
http://bimmer-toolset.com/forum/viewtopic.php?t=192
http://phpbb2.00web.net/profile.php?mode=viewprofile&u=42363
http://www.xn--4gqy36fjvemkm.com/forum.php?mod=viewthread&tid=365&extra=
http://bbs.epaqi.com/forum.php?mod=viewthread&tid=116108&extra=
http://www.mutterkind-kur.de/forum/viewtopic.php?f=39&t=1098242

Одним словом они молодцы и я их советую.
Вот их интернет ресурс где я оформлял продукцию.
Evacaj No. 9179 2025-09-28 15:35:37
Занимаюсь очищением уже более 10 лет.
И вот недавно прочитал информацию что пчелопродукты очень нужны и отлично повышают иммунитет.
Перечитав большое количество информации на сайте, я узнал много полезного для себя.
А так же нашел массу народных рецептов на основе продуктов пчелы.
Вот кстати несколько полезных статей:
http://seafishzone.com/home.php?mod=space&uid=2276535
http://cpmayencos.org/mercadillo/viewtopic.php?f=41&t=963
http://www.daveandspencer.com/forums/viewtopic.php?f=4&t=405227
http://forum.btcbr.info/viewtopic.php?t=153476
http://epaqi.com/forum.php?mod=viewthread&tid=116433&extra=

Думаю Вам будет полезно...
Evaaat No. 9181 2025-09-28 17:51:18
Занимаюсь очищением уже более 10 лет.
И вот недавно узнал информацию что продукты пчелы очень нужны и отлично укрепляют иммунитет.
Перечитав много информации на сайте, я узнал много полезного для себя.
А так же нашел массу народных рецептов на основе продуктов пчелы.
Вот кстати несколько хороших статей:
http://epaqi.com/forum.php?mod=viewthread&tid=116450&pid=118855&page=3&extra=#pid118855
http://epaqi.com/forum.php?mod=viewthread&tid=116342&extra=
http://bimmer-toolset.com/forum/viewtopic.php?t=214
http://www.xuduoqun.com/forum.php?mod=viewthread&tid=13490&extra=
http://epaqi.com/forum.php?mod=viewthread&tid=116450&pid=118850&page=3&extra=#pid118850

Думаю Вам будет полезно...
Davidryp No. 9183 2025-09-29 03:47:07
Вы читали что творится с Битком? Я был в ужасе как он стал дороже за последнее время.
И даже если будет спад я все равно буду покупать его и инвестировать.
Но чтоб поднять свой уровень финансовой грамотности, решил найти сайт, на котором смогу черпать информацию про все криптовалюты.
Мне понравился сайт. На данном портале я смог найти статьи про каждую криптовалюту из ТОП 200. Получил полную информацию как майнить крипту.
Вот одной из последних новостей хотел бы поделиться с Вами:
Также нашел советы инвесторов как расти на падающем рынке и как пережидать спад рынка.
Читайте и становитесь богаче и умней!!!
http://epaqi.com/forum.php?mod=viewthread&tid=116535&pid=119052&page=2&extra=#pid119052
http://www.carshowsociety.com/forum.php/topic,109664.new.html#new
http://seafishzone.com/home.php?mod=space&uid=2280418
http://bbs.epaqi.com/forum.php?mod=viewthread&tid=116632&pid=119286&page=3&extra=#pid119286
http://cpmayencos.org/mercadillo/viewtopic.php?f=10&t=1076
Davidyuw No. 9185 2025-09-29 06:08:09
Вы читали что происходит с Биткоином? Я был в шоке как он стал дороже за последнее время.
И даже если будет упадок я все равно буду докупать его и инвестировать.
Но чтоб поднять свой уровень финансовой грамотности, решил найти сайт, на котором смогу читать информацию про все криптовалюты.
Мне понравился сайт. На данном сайте я смог найти статьи про каждую криптовалюту из ТОП 200. Получил полную информацию как майнить криптовалюту.
Вот одной из последних новостей хотел бы поделиться с Вами:
Также нашел советы инвесторов как инвестировать на падающем рынке и как пережидать коррекцию рынка.
Читайте и становитесь богаче и умней!!!
http://epaqi.com/forum.php?mod=viewthread&tid=116507&extra=
http://www.mutterkind-kur.de/forum/viewtopic.php?f=33&t=1102408
http://cpmayencos.org/mercadillo/viewtopic.php?f=37&t=1056
http://forum.btcbr.info/viewtopic.php?t=153493
http://www.fabetghislain.free.fr/Pages/phpBB2/profile.php?mode=viewprofile&u=42
Alexslt No. 9187 2025-09-29 22:11:33
Последнее время не могу найти нормальную информацию чтоб получить независимое мнение по той или иной новости, в основном большая часть контролируема государством.
Вижу что сейчас на небольших СМИ новости более качественная.
Нашел и хочу поделиться: http://www.fabetghislain.free.fr/Pages/phpBB2/viewtopic.php?p=429#429
http://bbs.epaqi.com/forum.php?mod=viewthread&tid=116977&pid=120091&page=1&extra=#pid120091
http://www.c-strike.fakaheda.eu/forum/viewthread.php?thread_id=2809
http://www.c-strike.fakaheda.eu/forum/viewthread.php?thread_id=2816
http://bbs.epaqi.com/forum.php?mod=viewthread&tid=116977&pid=120096&page=1&extra=#pid120096

А где ищите ВЫ?
Alexmwi No. 9189 2025-09-30 00:40:20
Последнее время не могу найти нормальную информацию чтоб получить независимое мнение по той или иной информации, в основном большая часть контролируема государством.
Вижу что сейчас на небольших СМИ информация более качественная.
Нашел и хочу поделиться: http://www.theadultstories.net/viewtopic.php?t=560819
http://www.forum.jehovih.ru/viewtopic.php?t=626
http://www.alkwet.com/vb/showthread.php?t=30084&p=87516#post87516
http://forum.btcbr.info/viewtopic.php?t=154608
http://www.c-strike.fakaheda.eu/forum/viewthread.php?thread_id=2775

А где ищите ВЫ?
Ilushikqdv No. 9191 2025-09-30 15:55:26
Рекомендую Вам настоящую пасеку, на которой заказываю большой ассортимент продуктов пчеловодства как для себя таки для своих родственников.
Пчеловоды делают всю продукцию пчеловодства на отменно, советы как употреблять по важным вопросам дают. Очень много нужных статей на сайте, Вот несколько из них:
http://forum.btcbr.info/viewtopic.php?t=154050
http://epaqi.com/forum.php?mod=viewthread&tid=116810&pid=119751&page=4&extra=#pid119751
http://rfid-china.com/forum.php?mod=viewthread&tid=111132&extra=
http://bbs.epaqi.com/forum.php?mod=viewthread&tid=116710&pid=119481&page=4&extra=#pid119481
http://www.daenemark-freunde.de/viewtopic.php?t=3313

Одним словом они молодцы и я их рекомендую.
Вот их интернет ресурс где я оформлял иммуностимулирующие продукты
http://bbs.epaqi.com/forum.php?mod=viewthread&tid=116784&extra=
Ilushikaks No. 9194 2025-09-30 18:57:08
Рекомендую Вам настоящую пасеку, на которой покупаю большой ассортимент пчелопродукции как для себя таки для своих знакомых.
Пчеловоды высылают всю пчелопродукцию на отменно, консультации по важным вопросам дают. Очень много полезных статей на портале, Вот несколько из них:
http://cpmayencos.org/mercadillo/viewtopic.php?f=25&t=1187
http://havanahubfl.com/forum/index.php/topic,104.new.html#new
http://www.c-strike.fakaheda.eu/forum/viewthread.php?thread_id=2540
http://www.ycke.cc/thread-5119-1-1.html
http://hd18.cn/bbs/viewthread.php?tid=194150&extra=

Одним словом они молодцы и я их рекомендую.
Вот их портал где я оформлял пчелопродукты
http://bbs.epaqi.com/forum.php?mod=viewthread&tid=116726&extra=
Leonfcu No. 9197 2025-10-01 05:25:46
Как и многие наши соотечественники искал как поехать в Польшу и заработать денег.
Перечитал массу сайтов, пересмотрел много фильмов на Ютубе, но больше всего мне понравился ресурс hochuvpolshu.com.
На нем я нашел несколько вариантов для работы, вычитал отзывы и истории тех мужчин и женщин,
которые делятся своим опытом работы в Польше. Так же узнал как сделать документы.
И всегда это на одной сайте.
Вот одна из свежих и интересных статей:
http://1er-online.de/viewtopic.php?t=9115
http://www.c-strike.fakaheda.eu/forum/viewthread.php?thread_id=2656
http://epaqi.com/forum.php?mod=viewthread&tid=116885&extra=
http://georgiantheatre.ge/user/Leonafx/
http://www.alkwet.com/vb/showthread.php?t=29811&p=85233#post85233
Leonjls No. 9199 2025-10-01 08:48:57
Как и многие наши соотечественники искал как уехать в Польшу и заработать денег.
Перечитал массу интернет страниц, пересмотрел много фильмов на Youtube, но больше всего мне понравился ресурс hochuvpolshu.com.
На нем я нашел несколько вакансий для работы, вычитал отзывы и опыт тех мужчин и женщин,
которые делятся своим опытом жизни в Польше. Так же узнал как сделать документы.
И всегда это на одной сайте.
Вот одна из свежих и интересных статей:
http://www.mordheim.labibliotecanegra.net/viewtopic.php?f=9&t=385
http://www.c-strike.fakaheda.eu/forum/viewthread.php?thread_id=2735
http://bbs.epaqi.com/forum.php?mod=viewthread&tid=116935&pid=120042&page=4&extra=#pid120042
http://www.alkwet.com/vb/showthread.php?t=29844&p=85943#post85943
http://www.alkwet.com/vb/showthread.php?t=29991&p=87120#post87120