Skip to content

Commit

Permalink
Merge pull request #6 from Nhoya/develop
Browse files Browse the repository at this point in the history
0.4b
  • Loading branch information
Nhoya authored Jan 14, 2018
2 parents bde19fa + 642437a commit 1744278
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 18 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
# gOSINT [![Build Status](https://travis-ci.org/Nhoya/gOSINT.svg?branch=master)](https://travis-ci.org/Nhoya/gOSINT) [![GitHub stars](https://img.shields.io/github/stars/Nhoya/gOSINT.svg)](https://github.com/Nhoya/gOSINT/stargazers) [![GitHub forks](https://img.shields.io/github/forks/Nhoya/gOSINT.svg)](https://github.com/Nhoya/gOSINT/network) [![Twitter](https://img.shields.io/twitter/url/https/github.com/Nhoya/gOSINT.svg?style=social&style=plastic)](https://twitter.com/intent/tweet?text=Wow:&url=https%3A%2F%2Fgithub.com%2FNhoya%2FgOSINT)
OSINT framework in Go

**current version**: 0.4

**develop version**: 0.4a

you probably want to take a look at the develop branch for more updates.

## Introduction


gOSINT is a small OSINT framework in Golang, if you want, feel free to contribute!


Expand Down Expand Up @@ -139,3 +136,7 @@ ask confirmation before adding mail to search results
`gOSINT -m telegram --target [PublicGroupName]`

retrive message history for telegram public group

`gOSINT -m telegram --target [PublicGroupName] --dumpfile`

the output will be stored in a file, if the file is already populated it will resume from the last ID
5 changes: 3 additions & 2 deletions gOSINT.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/jessevdk/go-flags"
)

const ver = "v0.4a"
const ver = "v0.4b"

var opts struct {
Module string `short:"m" long:"module" description:"Specify module" choice:"pgp" choice:"pwnd" choice:"git" choice:"plainSearch" choice:"telegram"`
Expand All @@ -18,6 +18,7 @@ var opts struct {
Mail string `long:"mail" default:"" description:"Specify mail target (for pgp and pwnd module)"`
Path string `short:"p" long:"path" description:"Specify target path (for plainSearch module)"`
TgGrace int `long:"grace" default:"15" description:"Specify telegram messages grace period"`
DumpFile bool `long:"dumpfile" description:"Create and resume messages from dumpfile"`
Mode bool `short:"f" long:"full" description:"Make deep search using linked modules"`
Clone bool `short:"c" long:"clone" description:"Enable clone function for plainSearch module (need to specify repo URL)"`
Confirm bool `long:"ask-confirmation" description:"Ask confirmation before adding mail to set (for plainSearch module)"`
Expand Down Expand Up @@ -91,6 +92,6 @@ func main() {
fmt.Println("You must specify target")
os.Exit(1)
}
getTelegramGroupHistory(opts.Target, opts.TgGrace)
getTelegramGroupHistory(opts.Target, opts.TgGrace, opts.DumpFile)
}
}
57 changes: 45 additions & 12 deletions telegram.go
Original file line number Diff line number Diff line change
@@ -1,42 +1,58 @@
package main

import (
"bufio"
"fmt"
"github.com/jaytaylor/html2text"
"os"
"regexp"
"strconv"
"strings"
"time"

"github.com/jaytaylor/html2text"
)

func getTelegramGroupHistory(group string, grace int) {
i := 1
func getTelegramGroupHistory(group string, grace int, dumpFlag bool) {
graceCounter := 0
ret := ""
for i != 0 {
messageid := strconv.Itoa(i)
dumpfile := group + ".dump"
msgtxt := ""

fmt.Println("==== Dumping messages for " + group + " ====")
messageCounter := readFromTelegramDump(dumpfile, dumpFlag)
messageCounter++
for messageCounter != 0 {
messageid := strconv.Itoa(messageCounter)
body := retriveRequestBody("https://t.me/" + group + "/" + messageid + "?embed=1")
message := getTelegramMessage(body)

if message != "" {
for j := 0; j < graceCounter; j++ {
fmt.Println("[MESSAGE REMOVED]")
msg := "[MESSAGE REMOVED]"
writeOnFile(dumpfile, "["+strconv.Itoa(messageCounter-graceCounter+j)+"] "+msg+"\n")
fmt.Println(msg)
}

graceCounter = 0
username, nickname := getTelegramUsername(body)
date, time := getTelegramMessageDateTime(body)

if username == "" {
ret = "[" + date + " " + time + "] " + nickname + ": " + message
msgtxt = "[" + date + " " + time + "] " + nickname + ": " + message
} else {
ret = "[" + date + " " + time + "] " + nickname + "(" + username + "): " + message
msgtxt = "[" + date + " " + time + "] " + nickname + "(" + username + "): " + message
}
msg, _ := html2text.FromString(ret)

msg, _ := html2text.FromString(msgtxt)

writeOnFile(dumpfile, "["+messageid+"] "+msg+"\n")
fmt.Println(msg)
} else {
graceCounter++
if graceCounter == grace {
break
}
}
i++
messageCounter++
time.Sleep(time.Millisecond * 500)
}
}
Expand Down Expand Up @@ -88,7 +104,7 @@ func getTelegramVideo(body string) string {
}

func getTelegramUsername(body string) (string, string) {
re := regexp.MustCompile(`class=\"tgme_widget_message_author_name\" (?:href="https://t\.me/(\w+)")? dir=\"auto\">(.*)</a>&nbsp;in&nbsp;<a`)
re := regexp.MustCompile(`class=\"tgme_widget_message_author_name\"\s?(?:href="https://t\.me/(\w+)")? dir=\"auto\">(.*)<\/(?:span>)?(?:a>)?&nbsp;in&nbsp;<a`)
match := re.FindStringSubmatch(body)
return match[1], match[2]
}
Expand All @@ -98,3 +114,20 @@ func getTelegramMessageDateTime(body string) (string, string) {
match := re.FindStringSubmatch(body)
return match[1], match[2]
}

func readFromTelegramDump(dumpfile string, dumpFlag bool) int {
messageCounter := 0
if dumpFlag {
fmt.Println("The dump will be saved in " + dumpfile)
if fileExists(dumpfile) {
file, _ := os.Open(dumpfile)
scan := bufio.NewScanner(file)
for scan.Scan() {
messageSlice := strings.Split(scan.Text(), " ")
fmt.Println(strings.Join(messageSlice[1:], " "))
messageCounter, _ = strconv.Atoi(strings.Trim(messageSlice[0], "[]"))
}
}
}
return messageCounter
}
19 changes: 19 additions & 0 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,22 @@ func isUrl(url string) {
os.Exit(1)
}
}

func writeOnFile(filename string, text string) {
f, err := os.OpenFile(filename, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
fmt.Println("Unabale to open file")
os.Exit(1)
}
_, err = f.WriteString(text)
if err != nil {
fmt.Println("Unable to wite on file")
}
}

func fileExists(file string) bool {
if _, err := os.Stat(file); err == nil {
return true
}
return false
}

0 comments on commit 1744278

Please sign in to comment.