4

​ How could I recognize or identify with PHP or Javascript if a submitted code is equals to a Google Adsense code?

For example, I submit several javascript codes onto my website through a form, and the program should recognize when I submit a Google Adsense Code. How could it be possible? And I mean I submit any adsense code, the software would recognize it. Thanks for everyone in advance for any idea!

I'd like to solve the problem, but have no idea how to start.

Some ways I started thinking of (please do not read this before you have an idea, or it will confuse you)

I submit a code, and PHP checks if the code contains usual elements from the AdSense code. I realized this trial is bad, because a code can contain elements of the adsense code, but that can be expanded with unique elements, so the code still passes the check.

Another way I started thinking was to write a program that limits the input of a code, and the limitation is about the length of the adsense code, but I realized, that adsense code length changes from time to time.

Another way I was thinking of was to check manually whether it is adsense code submitted or not. Worst solution.

PsiX
  • 1,661
  • 1
  • 17
  • 35

1 Answers1

1

step 1. harvest all the javascript strings from the code sample.
step 2. merge all strings into one big string.
step 3. check for references to google adsense api or api key (UA-something-1 or so)
step 4. reverse the string
step 5. repeat step 3
step 6. mark as suspicious if found a suspicious match
step 7. human check for false positive

Tschallacka
  • 27,901
  • 14
  • 88
  • 133
  • Seems to be great solution. Are there any tutorials for this? As I am junior regarding javascript and PHP. Of course if there are no tutorials, I will google as much as I can. – Miklos Nagy Dec 19 '16 at 08:22
  • well, you need to parse the javascript code, strip the strings from it, discard the rest, and then check it. This of course will not help you against identify base64 encoded strings, but you could mark any code containing [atob](https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/atob) as suspcious needing an extra human check. [php-to-extract-a-string-from-double-quote](http://stackoverflow.com/questions/1017051/php-to-extract-a-string-from-double-quote) might help and http://stackoverflow.com/questions/4366730/how-to-check-if-a-string-contains-a-specific-word-in-php – Tschallacka Dec 19 '16 at 08:28
  • Thank you, I'll try. As long as the program can take the greater part of the task, it will be good. – Miklos Nagy Dec 19 '16 at 08:33
  • If this question answers your question you can consider accepting it(checkmark) or upvoting. that's how it works here on stack overflow, so others know that this helped you if they have a similar problem. – Tschallacka Dec 19 '16 at 08:45