Passed
Push — master ( 2e21e7...ed9e4b )
by Kris
01:49 queued 14s
created

ApiDefintion::getCategories()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

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