Selenium tests for pre-defined javascript variables which appear when executing selenium.
The detection scripts usually have word like "selenium" / "webdriver" in any of the variables and also the document variables called $cdc_ and $wdc_. All these depends on the browser you are using. Different browsers expose different things.
I used chrome all that I had to do was to ensure that $cdc_ didn't exist anymore as document variable, also download chrome driver source code, modify chrome driver and re-compile $cdc_ with different names.