I learned something new yesterday while working on a simple four column table that keeps a list of the favorite tools in NetScanTools Pro. This table was set up without a constraint meaning there is nothing stopping us from inserting a row that is identical to a current row. Here is the DDL for the table:
CREATE TABLE [favorites] (
[col1] NUMBER,
[col2] TEXT,
[col3] NUMBER,
[col4] NUMBER);
As you can see - no constraints.
While working with the right click menu that adds a tool to NetScanTools Pro I discovered that it was adding the same row twice. I was using an INSERT INTO favorites... SQL command. So I thought I would get rid of the duplicates by using INSERT OR REPLACE INTO favorites. Wrong.
What I didn't know/remember was that the OR REPLACE means to replace the rows that are causing a constraint violation. Since there is no constraint, there is no constraint violation meaning the OR REPLACE clause does nothing and multiple identical rows can still be inserted.
An obvious solution is to change the table and add a constraint like this:
CREATE TABLE [favorites] (
[col1] NUMBER,
[col2] TEXT,
[col3] NUMBER,
[col4] NUMBER,
CONSTRAINT [] PRIMARY KEY ([col1]) ON CONFLICT REPLACE);
But to do so in an installed base of software in the hands of customers would require changes: ie. copying the existing table, deleting the old table and recreating it with the constraint. Plus it would require checking every time the program is started to make sure it had been done or some other versioning method would have to be used. Lots of details.
I arrived at a different solution using a TRIGGER to remove duplicate rows before the INSERT happens. This requires no changes to the design of the table and does not require changing anything in the user's database. This statement creates a TEMPORARY TRIGGER if it does not already exist and does this before an INSERT happens. It deletes any rows that match 'new' col1, then does the INSERT.
CREATE TEMP TRIGGER IF NOT EXISTS [unique_row]
BEFORE INSERT
ON favorites
BEGIN
DELETE FROM favorites WHERE new.col1= col1;
END
Pretty simple and appears to get the job done without modifying the original table. TRIGGERS are very powerful and I will probably be using more of them in the future - but using them with care.
Thanks to Bogdan Ureche for help in understanding what was going on with INSERT OR REPLACE without a corresponding CONSTRAINT.
www.SQLite.org
A look at all things to do with NetScanTools® Products. Inside you will find tips and comments about using our programs and even off topic comments.
Tuesday, February 12, 2013
NetScanTools in Hacking for Dummies 4th Edition
Kevin Beaver wrote Hacking for Dummies and he has just completed the 4th edition. It's a well written comprehensive book on Ethical Hacking. He talks about hacking network hosts, operating systems, applications (communications, databases and websites), password cracking all from the perspective of a security consultant with permission to find the weaknesses in the targets. This can help you understand the dangers your computers or your business systems face from malicious hackers.
NetScanTools Pro is one of the tools he uses to demonstrate how you can assess vulnerabilities. While NetScanTools Pro is not designed as a hacking tool, it does have some tools that you can use to test for vulnerabilities.
Examples used in the book from NetScanTools Pro:
Using Ping Scanner to ping multiple IP addresses to find out what hosts are accessible.
Finding open ports with Port Scanner like the port 53 DNS, NetBIOS port 139, and SQL Server port 1434.
Scanning SNMP or dumping whole system's MIB trees using our SNMP tools.
Using the UDP Packet Flooder as a DoS testing tool.
Windows share enumeration using our Network Shares - SMB tool.
SMTP Relay Testing.
Get the book at dummies.com. ISBN 978-1-118-38093-2
NetScanTools Pro is one of the tools he uses to demonstrate how you can assess vulnerabilities. While NetScanTools Pro is not designed as a hacking tool, it does have some tools that you can use to test for vulnerabilities.
Examples used in the book from NetScanTools Pro:
Using Ping Scanner to ping multiple IP addresses to find out what hosts are accessible.
Finding open ports with Port Scanner like the port 53 DNS, NetBIOS port 139, and SQL Server port 1434.
Scanning SNMP or dumping whole system's MIB trees using our SNMP tools.
Using the UDP Packet Flooder as a DoS testing tool.
Windows share enumeration using our Network Shares - SMB tool.
SMTP Relay Testing.
Get the book at dummies.com. ISBN 978-1-118-38093-2
Tuesday, February 5, 2013
NetScanTools LE 1.51 Released
NetScanTools LE was updated to ensure Windows 8 compatibility. Some minor user interface changes were made, documents and databases updated. Whois now has better support for looking up IPv6 addresses.
Please visit http://www.netscantools-le.com/ for more information.
Please visit http://www.netscantools-le.com/ for more information.
Thursday, January 31, 2013
January NetScanTools Newsletter Ready
The January edition of the NetScanTools Newsletter is ready. Topics include version app release announcements and how to effectively use the Ping Sweep function of the Managed Switch Port Mapping Tool on a large subnet.
Also a preview of what we are working on for NetScanTools Pro 11.5...
http://www.netscantools.com/newsletters.html
Also a preview of what we are working on for NetScanTools Pro 11.5...
http://www.netscantools.com/newsletters.html
Thursday, January 24, 2013
End of January Sale
End of January sale. Use the coupon jan2013 to get 25% off NetScanTools Pro bundled with the Managed Switch Port Mapping Tool or just the Managed Switch Port Mapping Tool now through Sunday January 27, 2013:
NetScanTools Pro/Managed Switch Port Mapping Tool Bundle:
https://www.plimus.com/jsp/buynow.jsp?contractId=1669078
Managed Switch Port Mapping Tool only:
https://www.plimus.com/jsp/buynow.jsp?contractId=1661161
NetScanTools Pro/Managed Switch Port Mapping Tool Bundle:
https://www.plimus.com/jsp/buynow.jsp?contractId=1669078
Managed Switch Port Mapping Tool only:
https://www.plimus.com/jsp/buynow.jsp?contractId=1661161
Wednesday, January 9, 2013
New SSL Certificate Scanner on video
NetScanTools Pro v11.40 now includes a new tool called the SSL Certificate Scanner. Use it to collect and verify the expiration status of SSL certificates on a list of https secure web servers. Here is a video overview of the tool.
How to save XML results files from Switch Lists
This question has come up frequently from people who are using Managed Switch Port Mapping Tool v2.x in Switch List mode (this mode means two or more switches are mapped in succession).
To make individual XML files for each switch as it goes, go to the Switch List Editor and make sure 'save switch results as xml files after each switch mapping' is checked. This setting is different for each separate switch list and should be on by default.
Next, change your command line to:
spmap.exe -maplist TheSwitchListName -postexit
This tells the app to map the named list and exit when complete.
Here is the part people have a problem with: The files will be saved to either My Documents or the last used directory you saved XML files to from the menu.
You can override the path manually by mapping any switch or reloading results from history, then right click and select Export XML. Save the results to the directory you want everything to go to. When you run the switch list, it will save in that last location.
The XML filenames will have the format:
switch-ip_a.ip_b.ip_c.ip_d-unixTimestamp.xml
Please be aware that the command line option -xml D:\switch.xml only works for a single switch.
This will be documented more fully in a subsequent release. You can get the application at http://www.SwitchPortMapper.com/
To make individual XML files for each switch as it goes, go to the Switch List Editor and make sure 'save switch results as xml files after each switch mapping' is checked. This setting is different for each separate switch list and should be on by default.
Next, change your command line to:
spmap.exe -maplist TheSwitchListName -postexit
This tells the app to map the named list and exit when complete.
Here is the part people have a problem with: The files will be saved to either My Documents or the last used directory you saved XML files to from the menu.
You can override the path manually by mapping any switch or reloading results from history, then right click and select Export XML. Save the results to the directory you want everything to go to. When you run the switch list, it will save in that last location.
The XML filenames will have the format:
switch-ip_a.ip_b.ip_c.ip_d-unixTimestamp.xml
Please be aware that the command line option -xml D:\switch.xml only works for a single switch.
This will be documented more fully in a subsequent release. You can get the application at http://www.SwitchPortMapper.com/
Labels:
command line,
Switch List,
Switch Port Mapper,
XML
Subscribe to:
Posts (Atom)