# TrojanSourceFinder | Help Find Trojan Source Vulnerability In Code

**URL:** <https://onehack.st/t/trojansourcefinder-help-find-trojan-source-vulnerability-in-code/210672>\
**Category:** Tools & Scripts\
**Tags:** tools, programming\
**Created:** [December 28, 2021, 3:52pm UTC](https://onehack.st/t/trojansourcefinder-help-find-trojan-source-vulnerability-in-code/210672 "2021-12-28T15:52:51Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![WhiteHat](https://onehack.st/user_avatar/onehack.st/whitehat/32/162514_2.png) [@WhiteHat](https://onehack.st/u/WhiteHat)\
**Post date:** [December 28, 2021, 3:52pm UTC](https://onehack.st/t/trojansourcefinder-help-find-trojan-source-vulnerability-in-code/210672/1 "2021-12-28T15:52:52Z")

</div>

#### TrojanSourceFinder helps developers detect “Trojan Source” vulnerability in source code.

Trojan Source vulnerability allows an attacker to make malicious code appear innocent. In general, the attacker tries to lure by passing his code off as a comment (visually). It is a serious threat because it concerns many languages. Projects with multiple “untrusted” sources could be concerned

**[Detect evil 🔎](https://github.com/ariary/TrojanSourceFinder#detect-trojan-source) · [Track evil 👀](https://github.com/ariary/TrojanSourceFinder#visualize-trojan-source) · [Trojan Source ❓](https://github.com/ariary/TrojanSourceFinder/blob/main/TrojanSource.md)**

## Install

### With `go`

_\> Via `go install`_

go install [github.com/ariary/TrojanSourceFinder/cmd/tsfinder@latest](http://github.com/ariary/TrojanSourceFinder/cmd/tsfinder@latest)

Make sure `$GOPATH` is in your `$PATH`

_\> From source_

git clone [https://github.com/ariary/TrojanSourceFinder](https://github.com/ariary/TrojanSourceFinder) cd TrojanSourceFinder make before.build make build.tsfinder

If the command `make build.tsfinder` failed, try:

env GOOS=target-OS GOARCH=target-architecture go build -o tsfinder cmd/main.go

### With `curl`

_\> From release_

curl -lO -L [https://github.com/ariary/TrojanSourceFinder/releases/latest/download/tsfinder](https://github.com/ariary/TrojanSourceFinder/releases/latest/download/tsfinder) && chmod +x tsfinder

## Detect Trojan Source

_\> Help the detection of Trojan source for manual code review or with CI/CD pipelines (Unicode bidirectional characaters)_

To detect Trojan source in file or directory :

tsfinder [path]

### Detect only in text file

_\> Source code files are likely text files. Withdraw them for scan could help to rule out false positives_

tsfinder -t [path]

Add `-v` help to see which file has been skipped by scan.

### Go further _(Homoglyph)_

Trojan Source is not new and isn’t the only hazard. Another one is _“Homoglyph”_.(_[Kezako?](https://github.com/ariary/TrojanSourceFinder/blob/main/TrojanSource.md#homoglyph)_)

tsfinder help detecting them with `homoglyph` command:

tsfinder homoglyph [filename] [flags]

You could see if there is a sibling (ie word with same “skeleton”) for the homographs found in `path` using the flag `--sibling`:

tsfinder homoglyph [filename] --sibling [path]

_Functionality under development, mainly depending on other project_

## Visualize Trojan Source

_\> Visualize how the code is really interpreted by machines/compiler_

_tsfinder_ is deliberately not very verbose. By default, it will only output if Trojan Source code has been detected. To have more verbosity and **visualize the dangerous line add the flag `-v`**.

To better see where Trojan Sources were, you could enable colored output with `-c` flag (also useful with directory scan):

tsfinder -c -v

## Demo

[![demo](https://github.com/ariary/TrojanSourceFinder/raw/main/img/tsfinder-demo-trojansource.gif)](https://github.com/ariary/TrojanSourceFinder/blob/main/img/tsfinder-demo-trojansource.gif)

### Homoglyph

[![demo](https://github.com/ariary/TrojanSourceFinder/raw/main/img/tsfinder-demo-homoglyph.gif)](https://github.com/ariary/TrojanSourceFinder/blob/main/img/tsfinder-demo-homoglyph.gif)

## Alternative

As mentioned by `@ioah86` [here](https://www.reddit.com/r/cybersecurity/comments/qlh5j9/my_take_on_trojan_source/), trojan source could also been detected w/ a one liner using grep.

The big difference is the output format and the exit status code (`tsfinder` exit with status code `0` if no Trojan source has been found, `1` otherwise; the opposite for `grep`)

Also, this one-liner does not resolve the homoglyph issue

| Goal | `tsfinder` | `grep` one-liner |
| --- | --- | --- |
| Scan all files + show lines | `tsfinder -v .` | `grep -arE ` |
| Scan only on human-readable files | `tsfinder -t .` | `grep -IrE ` |
| Exit with status code 1 if found | default | `[one-liner] && exit 1 |
| Scan only on human-readable files | `DISCOURSE_PLACEHOLDER_22` | `DISCOURSE_PLACEHOLDER_23` |
| Exit with status code 1 if found | default | `DISCOURSE_PLACEHOLDER_24` |
| Exit with status code 1 if found | default | `DISCOURSE_PLACEHOLDER_24` |
| Scan only on human-readable files | `DISCOURSE_PLACEHOLDER_22` | `DISCOURSE_PLACEHOLDER_23` |
| Exit with status code 1 if found | default | `DISCOURSE_PLACEHOLDER_24` |

## GitHub:

[https://github.com/ariary/TrojanSourceFinder](https://github.com/ariary/TrojanSourceFinder)
