|
| 1 | +package main |
| 2 | + |
| 3 | +import ( |
| 4 | +"fmt" |
| 5 | +"net/http" |
| 6 | +"os" |
| 7 | +"strings" |
| 8 | + |
| 9 | +"github.com/akamensky/argparse" |
| 10 | +"github.com/common-nighthawk/go-figure" |
| 11 | +"github.com/fatih/color" |
| 12 | +tw "github.com/olekukonko/tablewriter" |
| 13 | +cf "github.com/redcode-labs/Coldfire" |
| 14 | +) |
| 15 | + |
| 16 | +func findRedirects(url string) { |
| 17 | +if !strings.Contains(url, "https://") && !strings.Contains(url, "http:") { |
| 18 | +url = "https://" + url |
| 19 | +} |
| 20 | +var tableData [][]string |
| 21 | +nextUrl := url |
| 22 | +for i := 0; i < 50; i++ { |
| 23 | +redir := &http.Client{CheckRedirect: func(req *http.Request, via []*http.Request) error { |
| 24 | +return http.ErrUseLastResponse |
| 25 | +}} |
| 26 | +res, err := redir.Get(nextUrl) |
| 27 | +if err != nil { |
| 28 | +cf.PrintError(err.Error()) |
| 29 | +} |
| 30 | +nextUrl = res.Header.Get("Location") |
| 31 | +sc := cf.IntToStr(res.StatusCode) |
| 32 | +urlColor := cf.Red |
| 33 | +u := nextUrl |
| 34 | +if sc == "200" { |
| 35 | +urlColor = cf.Green |
| 36 | +u = url |
| 37 | +} |
| 38 | +id := cf.IntToStr(i) |
| 39 | +tableData = append(tableData, []string{id, urlColor(u), sc}) |
| 40 | +if sc == "200" { |
| 41 | +break |
| 42 | +} |
| 43 | +} |
| 44 | +table := tw.NewWriter(os.Stdout) |
| 45 | +table.SetHeader([]string{"ID", "URL", "STATUS CODE"}) |
| 46 | +table.SetAutoWrapText(false) |
| 47 | +table.SetCenterSeparator("*") |
| 48 | +table.SetAlignment(tw.ALIGN_CENTER) |
| 49 | +table.SetRowSeparator("-") |
| 50 | +for v := range tableData { |
| 51 | +table.Append(tableData[v]) |
| 52 | +} |
| 53 | +if len(tableData) != 0 { |
| 54 | +fmt.Println("") |
| 55 | +cf.PrintInfo("URL => " + url) |
| 56 | +table.Render() |
| 57 | +fmt.Println("") |
| 58 | +} |
| 59 | +} |
| 60 | + |
| 61 | +func printBanner() { |
| 62 | +banner := figure.NewFigure("UnChain", "", true) |
| 63 | +color.Set(color.FgMagenta) |
| 64 | +fmt.Println("") |
| 65 | +banner.Print() |
| 66 | +color.Unset() |
| 67 | +fmt.Println("") |
| 68 | +fmt.Println("\tCreated by: redcodelabs.io " + cf.Red("<*>")) |
| 69 | +fmt.Println("") |
| 70 | +} |
| 71 | + |
| 72 | +func main() { |
| 73 | +printBanner() |
| 74 | +parser := argparse.NewParser("unchain", "") |
| 75 | +var URLS = parser.String("u", "url", &argparse.Options{Required: true, Help: "File containing urls or a single url"}) |
| 76 | +err := parser.Parse(os.Args) |
| 77 | +cf.ExitOnError(err) |
| 78 | +var urls []string |
| 79 | +if cf.Exists(*URLS) { |
| 80 | +urls = cf.FileToSlice(*URLS) |
| 81 | +} else { |
| 82 | +urls = []string{*URLS} |
| 83 | +} |
| 84 | +for _, u := range urls { |
| 85 | +findRedirects(u) |
| 86 | +} |
| 87 | +} |
0 commit comments