Code Monkey home page Code Monkey logo

cloudflare-origin-ip's Introduction

cloudflare-origin-ip

Try to find the origin IP of a webapp protected by Cloudflare.

python badge MIT license badge twitter badge


Description

This Python tool compares the HTTP response of the given subdomain to HTTP responses of a list of IPs addresses. This list is based on:

  • subdomains supplied by the user
  • subdomains found on external sources
  • IPs found external sources

Then, a score of similarity is calculated for each response using the Levenshtein algorithm.

Install

git clone https://github.com/gwen001/cloudflare-origin-ip
cd cloudflare-origin-ip
pip3 install -r requirements.txt

Depending the sources you want to use, you'll need to create environment variables:

  • Censys: CENSYS_UID and CENSYS_SECRET
  • SecurityTrails: SECURITY_TRAILS_API_KEY

Usage

$ python3 cloudflare-origin-ip.py <url>
usage: cloudflare-origin-ip.py [-h] [-u URL] [-s SOURCE]

options:
  -h, --help            show this help message and exit
  -u URL, --url URL     url to test
  -s SOURCE, --source SOURCE
                        datas sources separated by coma, can be: censys,crtsh,securitytrails,local file

Examples:
cloudflare-origin-ip.py -u https://xxx.xxxxxxxxxxxx.xxx
cloudflare-origin-ip.py -u https://xxx.xxxxxxxxxxxx.xxx -s censys,crtsh,securitytrails (default)
cloudflare-origin-ip.py -u https://xxx.xxxxxxxxxxxx.xxx -s /home/local/ips.txt
cloudflare-origin-ip.py -u https://xxx.xxxxxxxxxxxx.xxx -s censys,crtsh,/home/local/ips.txt,/home/local/subdomains.txt

How it works

1/ Performs a HTTP request to the URL provided, this is the reference request.

2/ Grabs IPs using several sources:

  • censys (key required)
  • crtsh
  • securitytrails (key required)
  • local file

3/ Performs a HTTP request to all IPs grabbed with the header Host setted to the subdomain of the reference request.

4/ Compares the responses obtained with the response of the reference request using the Levenshtein algorithm.

5/ Displays a score of similarity.



Feel free to open an issue if you have any problem with the script.

cloudflare-origin-ip's People

Contributors

gwen001 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

cloudflare-origin-ip's Issues

Giving Error

When I use the format:

python3 cloudflare-origin-ip.py -u xyz.com

It gives me following error:

Error: 'CENSYS_UID' not defined
To fix this:
export CENSYS_UID=xxxxxxxxxxxxxxxxxxxxxxxxxx
export CENSYS_SECRET=xxxxxxxxxxxxxxxxxxxxxxx

Division by zero

Very similar to the previous one

Traceback (most recent call last):
  File "/app/cloudflare-origin-ip.py", line 585, in <module>
    pool.map( partial(testBypass3,t_multiproc,r_reference,host), t_ips )
  File "/usr/local/lib/python3.12/multiprocessing/pool.py", line 367, in map
    return self._map_async(func, iterable, mapstar, chunksize).get()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/multiprocessing/pool.py", line 774, in get
    raise self._value
  File "/usr/local/lib/python3.12/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
                    ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/multiprocessing/pool.py", line 48, in mapstar
    return list(map(*args))
           ^^^^^^^^^^^^^^^^
  File "/app/cloudflare-origin-ip.py", line 458, in testBypass3
    score = responseCompare( r_reference, r )
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/cloudflare-origin-ip.py", line 487, in responseCompare
    score['dist_content_type'] = 100 - ( dist*100 / len(r_reference.headers['Content-Type']) )
                                         ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

SSL error

[+] 5 ips added
[+] 2 unique ips collected
[+] Performing reference request...
Status=200, Length=2894, Headers=13, Content-Type=text/html; charset=utf-8
[+] Testing bypass...
172.67.195.141 is CloudFlare
[-] 170.187.131.209: HTTPSConnectionPool(host='170.187.131.209', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLError(1, '[SSL: TLSV1_ALERT_INTERNAL_ERROR] tlsv1 alert internal error (_ssl.c:992)')))
[ cloudflare-origin-ip]$

Response content size can be zero

[+] Reading datas from file: ips
[+] 0 subdomains found, 27 ips added
[+] 27 unique ips collected
[+] Performing reference request...
Status=404, Length=0, Headers=9, Content-Type=text/plain; charset=utf-8
[+] Testing bypass...
[-] 40.126.38.21: Exceeded 30 redirects.
Traceback (most recent call last):
  File "/app/cloudflare-origin-ip.py", line 584, in <module>
    pool.map( partial(testBypass3,t_multiproc,r_reference,host), t_ips )
  File "/usr/local/lib/python3.12/multiprocessing/pool.py", line 367, in map
    return self._map_async(func, iterable, mapstar, chunksize).get()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/multiprocessing/pool.py", line 774, in get
    raise self._value
  File "/usr/local/lib/python3.12/multiprocessing/pool.py", line 125, in worker
    result = (True, func(*args, **kwds))
                    ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.12/multiprocessing/pool.py", line 48, in mapstar
    return list(map(*args))
           ^^^^^^^^^^^^^^^^
  File "/app/cloudflare-origin-ip.py", line 458, in testBypass3
    score = responseCompare( r_reference, r )
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/cloudflare-origin-ip.py", line 490, in responseCompare
    score['dist_content'] = 100 - ( dist*100 / len(r_reference.content[0:COMPARE_FIRST_CHARS]) )
                                    ~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
ZeroDivisionError: division by zero

Getting these errors

pool.map( partial(testBypass3,t_multiproc,r_reference,host), t_ips )
File "/usr/lib/python3.11/multiprocessing/pool.py", line 367, in map
return self._map_async(func, iterable, mapstar, chunksize).get()
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/multiprocessing/pool.py", line 774, in get
raise self._value
File "/usr/lib/python3.11/multiprocessing/pool.py", line 125, in worker
result = (True, func(*args, **kwds))
^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3.11/multiprocessing/pool.py", line 48, in mapstar
return list(map(*args))
^^^^^^^^^^^^^^^^
line 313, in testBypass3
if is_cloudflare3( IPAddress(ip) ):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
line 247, in is_cloudflare3
ip = IP2Int( str(ip) )
^^^^^^^^^^^^^^^^^
], line 132, in IP2Int
o = list( map(int, ip.split('.')) )
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ValueError: invalid literal for int() with base 10: '2606:4700:10::6814:4dc5'

NameError: name 'ip' is not defined

Can someone suggest a fix for this?

Traceback (most recent call last):
File "cloudflare-origin-ip.py", line 559, in
grabber_securitytrails( domain )
File "cloudflare-origin-ip.py", line 275, in grabber_securitytrails
if not ip in t_ips:
NameError: name 'ip' is not defined

api error

[-] error occured: CENSYS_UID or CENSYS_SECRET not found, Censys removed from sources
[-] error occured: SECURITY_TRAILS_API_KEY not found, SecurityTrails removed from sources

add shodn too ,please update

Facing error while running the tool

python3 cloudflare-origin-ip.py
Traceback (most recent call last):
File "/home/kali/Downloads/tools/cloudflare-origin-ip/cloudflare-origin-ip.py", line 6, in
import requests
File "/usr/lib/python3/dist-packages/requests/init.py", line 43, in
import urllib3
File "/home/kali/.local/lib/python3.11/site-packages/urllib3/init.py", line 8, in
from .connectionpool import (
File "/home/kali/.local/lib/python3.11/site-packages/urllib3/connectionpool.py", line 29, in
from .connection import (
File "/home/kali/.local/lib/python3.11/site-packages/urllib3/connection.py", line 39, in
from .util.ssl_ import (
File "/home/kali/.local/lib/python3.11/site-packages/urllib3/util/init.py", line 3, in
from .connection import is_connection_dropped
File "/home/kali/.local/lib/python3.11/site-packages/urllib3/util/connection.py", line 3, in
from .wait import wait_for_read
File "/home/kali/.local/lib/python3.11/site-packages/urllib3/util/wait.py", line 1, in
from .selectors import (
File "/home/kali/.local/lib/python3.11/site-packages/urllib3/util/selectors.py", line 14, in
from collections import namedtuple, Mapping
ImportError: cannot import name 'Mapping' from 'collections' (/usr/lib/python3.11/collections/init.py)

not running

Hi i added api and secret key still shwoing error

Error: 'CENSYS_UID' not defined
To fix this:
export CENSYS_UID=
export CENSYS_SECRET=

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.