Passed
Push — master ( eff0ac...d17b5e )
by Kris
01:35
created

ApiDefintion::getCategoryIdbyName()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 10
rs 10
cc 3
nc 3
nop 1
1
<?php
2
3
/**
4
 *     _    _                    ___ ____  ____  ____
5
 *    / \  | |__  _   _ ___  ___|_ _|  _ \|  _ \| __ )
6
 *   / _ \ | '_ \| | | / __|/ _ \| || |_) | | | |  _ \
7
 *  / ___ \| |_) | |_| \__ \  __/| ||  __/| |_| | |_) |
8
 * /_/   \_\_.__/ \__,_|___/\___|___|_|   |____/|____/
9
 *
10
 * This file is part of Kristuff\AbsuseIPDB.
11
 *
12
 * (c) Kristuff <[email protected]>
13
 *
14
 * For the full copyright and license information, please view the LICENSE
15
 * file that was distributed with this source code.
16
 *
17
 * @version    0.1.0
18
 * @copyright  2020 Kristuff
19
 */
20
21
namespace Kristuff\AbuseIPDB;
22
23
/**
24
 * Class ApiDefintion
25
 * 
26
 * Abstract base class for ApiManager
27
 * Contains main hard coded api settings
28
 */
29
abstract class ApiDefintion
30
{
31
     /**
32
     * AbuseIPDB API v2 Endpoint
33
     * @var string $api_endpoint  
34
     */
35
    protected $aipdbApiEndpoint = 'https://api.abuseipdb.com/api/v2/'; 
36
37
    /**
38
     * AbuseIPDB API v2 categories
39
     * @var array $aipdbApiCategories
40
     */
41
    protected $aipdbApiCategories = [
42
        
43
        // Altering DNS records resulting in improper redirection.        
44
        ['dns-c'           , '1', 'DNS Compromise', true],    
45
        
46
        // Falsifying domain server cache (cache poisoning).
47
        ['dns-p'           , '2', 'DNS Poisoning', true],     
48
        
49
        // Fraudulent orders.
50
        ['fraud-orders'    , '3', 'Fraud Orders', true],      
51
52
        // Participating in distributed denial-of-service (usually part of botnet).        
53
        ['ddos'            , '4', 'DDoS Attack', true],       
54
        
55
        // 
56
        ['ftp-bf'          , '5', 'FTP Brute-Force', true],   
57
        
58
        // Oversized IP packet.
59
        ['pingdeath'       , '6', 'Ping of Death', true],     
60
61
        // Phishing websites and/or email.
62
        ['phishing'        , '7', 'Phishing', true],          
63
        
64
        //
65
        ['fraudvoip'       , '8', 'Fraud VoIP', true],        
66
67
        // Open proxy, open relay, or Tor exit node.
68
        ['openproxy'       , '9', 'Open Proxy', true],        
69
70
         // Comment/forum spam, HTTP referer spam, or other CMS spam.
71
         ['webspam'         , '10', 'Web Spam', true],        
72
73
        // Spam email content, infected attachments, and phishing emails. Note: Limit comments to only relevent
74
        // information (instead of log dumps) and be sure to remove PII if you want to remain anonymous.
75
        ['emailspam'       , '11', 'Email Spam', true],                                                   
76
             
77
        // CMS blog comment spam.
78
        ['blogspam'        , '12', 'Blog Spam', true],      
79
        
80
        // Conjunctive category.
81
        ['vpnip'           , '13', 'VPN IP', false], // to check alone ??           
82
83
        // Scanning for open ports and vulnerable services.
84
        ['scan'            , '14', 'Port Scan', true],        
85
       
86
        // seems to can't be used alone
87
        ['hack'            , '15', 'Hacking', false],           
88
89
        // Attempts at SQL injection.
90
        ['sql'             , '16', 'SQL Injection', true],     
91
        
92
        // Email sender spoofing.
93
        ['spoof'           , '17', 'Spoofing', true],         
94
95
        // Credential brute-force attacks on webpage logins and services like SSH, FTP, SIP, SMTP, RDP, etc. 
96
        // This category is seperate from DDoS attacks.
97
        ['brute'           , '18', 'Brute-Force', true],     
98
99
        // Webpage scraping (for email addresses, content, etc) and crawlers that do not honor robots.txt.                                  
100
        // Excessive requests and user agent spoofing can also be reported here.                        
101
        ['badbot'          , '19', 'Bad Web Bot', true],      
102
                                                         
103
        // Host is likely infected with malware and being used for other attacks or to host malicious content. 
104
        // The host owner may not be aware of the compromise. This category is often used in combination 
105
        // with other attack categories.
106
        ['explhost'        , '20', 'Exploited Host', true],
107
        
108
        // Attempts to probe for or exploit installed web applications such as a CMS 
109
        // like WordPress/Drupal, e-commerce solutions, forum software, phpMyAdmin and 
110
        // various other software plugins/solutions.                                                         
111
        ['webattack'       , '21', 'Web App Attack', true ],   
112
        
113
        // Secure Shell (SSH) abuse. Use this category in combination 
114
        // with more specific categories.
115
        ['ssh'             , '22', 'SSH', false],              
116
117
        // Abuse was targeted at an "Internet of Things" type device. Include 
118
        // information about what type of device was targeted in the comments.         
119
        ['oit'             , '23', 'IoT Targeted', true],     
120
      ];
121
122
    /**
123
     * Get the category id corresponding to given name
124
     * 
125
     * @access protected
126
     * @param string $categoryName    The report categoriy name
127
     * 
128
     * @return string|bool            The category id in string format if found, otherwise false
129
     */
130
    protected function getCategoryIdbyName(string $categoryName)
131
    {
132
        foreach ($this->aipdbApiCategories as $cat){
133
            if ($cat[0] === $categoryName) {
134
                return $cat;
135
            }
136
         }
137
138
        // not found
139
        return false;
140
    }
141
142
    /**
143
     * Get the category name corresponding to given id
144
     * 
145
     * @access protected
146
     * @param string    $categoryId   The report category id
147
     * 
148
     * @return string|bool            The category name if found, otherwise false
149
     */
150
    protected function getCategoryNameById(string $categoryId)
151
    {
152
        foreach ($this->aipdbApiCategories as $cat){
153
           if ($cat[1] === $categoryId) {
154
               return $cat;
155
           }
156
        }
157
158
        // not found
159
        return false;
160
    }
161
162
    /**
163
     * Get the index of category corresponding to given value
164
     * 
165
     * @access protected
166
     * @param string    $value          The report category id
167
     * @param string    $index          The index in value array 
168
     * 
169
     * @return int|bool                 The category index if found, otherwise false
170
     */
171
    protected function getCategoryIndex(string $value, int $index)
172
    {
173
        $i = -1;
174
        foreach ($this->aipdbApiCategories as $cat){
175
            
176
            $i++;
177
178
            if ($cat[$index] === $value) {
179
                return $i;
180
            }
181
         }
182
183
        // not found
184
        return false;
185
    }
186
187
}