CVE-2023-40173: Insufficiently Protected Credentials (CWE-522)
value: Social media skeleton is an uncompleted/framework social media project implemented using a php, css ,javascript and html. Prior to version 1.0.5 Social media skeleton did not properly salt passwords leaving user passwords susceptible to cracking should an attacker gain access to hashed passwords. This issue has been addressed in version 1.0.5 and users are advised to upgrade. There are no known workarounds for this issue.
CWE description: The product transmits or stores authentication credentials, but it uses an insecure method that is susceptible to unauthorized interception and/or retrieval.
CVSS v3 base score: 7.5
Published: 2023-08-18T22:15Z
Repository: https://github.com/fobybus/social-media-skeleton
Language: SQL
Files changed: sql/pipago_db.sql
Commit date: 2023-08-15 06:06:34 -0700
Commit message: added salting tables and modified password for default users

Diff: diff --git a/sql/pipago_db.sql b/sql/pipago_db.sql
index 630f730..e818975 100644
--- a/sql/pipago_db.sql
+++ b/sql/pipago_db.sql
@@ -1,11 +1,12 @@
+-- use password123 for both normal and admin user 
 -- phpMyAdmin SQL Dump
 -- version 5.1.3
 -- https://www.phpmyadmin.net/
 --
 -- Host: 127.0.0.1
--- Generation Time: Apr 25, 2022 at 04:18 PM
+-- Generation Time: Aug 15, 2023 at 03:01 PM
 -- Server version: 10.4.24-MariaDB
 -- PHP Version: 7.4.28
 
 SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
 START TRANSACTION;
@@ -38,11 +39,30 @@ CREATE TABLE `admin` (
 --
 -- Dumping data for table `admin`
 --
 
 INSERT INTO `admin` (`admin_id`, `email`, `password`) VALUES
-(1000, 'admin1@pipago.com', 'admin1login');
+(1000, 'admin@pipago.com', '86dd76e74017a9a4856c5c6d6937e471fa6f80f41b720428c0a73610d7dbbe75');
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `adminsalt`
+--
+
+CREATE TABLE `adminsalt` (
+  `sid` int(11) NOT NULL COMMENT 'salt id',
+  `aid` int(11) NOT NULL COMMENT 'admin id',
+  `salt` varchar(32) NOT NULL COMMENT 'salt'
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
+--
+-- Dumping data for table `adminsalt`
+--
+
+INSERT INTO `adminsalt` (`sid`, `aid`, `salt`) VALUES
+(1, 1000, '65c53cd5c62fec1766ad6bef6aac1253');
 
 -- --------------------------------------------------------
 
 --
 -- Table structure for table `blocking`
@@ -156,11 +176,30 @@ CREATE TABLE `users` (
 --
 -- Dumping data for table `users`
 --
 
 INSERT INTO `users` (`id`, `fname`, `lname`, `bday`, `city`, `email`, `password`, `gender`, `edu`, `last_seen`, `joined`, `avatar`) VALUES
-(1001, 'firaol', 'wakuma', '2022-04-21', 'addis abeba ', 'firaol@email.com', 'password123', 'male', 'is', '2022-04-25 14:47:39', '2022-04-25 14:47:39', '');
+(1001, 'firaol', 'wakuma', '2022-04-21', 'addis abeba ', 'firaol@email.com', '49620aa0869973f5584dbdefc5c50b23646cab16e3f16a5cbe27cfd1a81d55d7', 'male', 'is', '2023-08-15 11:40:15', '2022-04-25 14:47:39', '');
+
+-- --------------------------------------------------------
+
+--
+-- Table structure for table `usersalt`
+--
+
+CREATE TABLE `usersalt` (
+  `sid` int(11) NOT NULL COMMENT 'salt id',
+  `uid` int(11) NOT NULL COMMENT 'user id',
+  `salt` varchar(32) NOT NULL
+) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
+
+--
+-- Dumping data for table `usersalt`
+--
+
+INSERT INTO `usersalt` (`sid`, `uid`, `salt`) VALUES
+(1, 1001, '00e7a17d32f03da112294fbed42f3c4c');
 
 --
 -- Indexes for dumped tables
 --
 
@@ -168,10 +207,17 @@ INSERT INTO `users` (`id`, `fname`, `lname`, `bday`, `city`, `email`, `password`
 -- Indexes for table `admin`
 --
 ALTER TABLE `admin`
   ADD PRIMARY KEY (`admin_id`);
 
+--
+-- Indexes for table `adminsalt`
+--
+ALTER TABLE `adminsalt`
+  ADD PRIMARY KEY (`sid`),
+  ADD KEY `aid` (`aid`);
+
 --
 -- Indexes for table `blocking`
 --
 ALTER TABLE `blocking`
   ADD PRIMARY KEY (`bid`),
@@ -227,20 +273,33 @@ ALTER TABLE `post`
 -- Indexes for table `users`
 --
 ALTER TABLE `users`
   ADD PRIMARY KEY (`id`);
 
+--
+-- Indexes for table `usersalt`
+--
+ALTER TABLE `usersalt`
+  ADD PRIMARY KEY (`sid`),
+  ADD KEY `uid` (`uid`);
+
 --
 -- AUTO_INCREMENT for dumped tables
 --
 
 --
 -- AUTO_INCREMENT for table `admin`
 --
 ALTER TABLE `admin`
   MODIFY `admin_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=1037;
 
+--
+-- AUTO_INCREMENT for table `adminsalt`
+--
+ALTER TABLE `adminsalt`
+  MODIFY `sid` int(11) NOT NULL AUTO_INCREMENT COMMENT 'salt id', AUTO_INCREMENT=2;
+
 --
 -- AUTO_INCREMENT for table `blocking`
 --
 ALTER TABLE `blocking`
   MODIFY `bid` int(11) NOT NULL AUTO_INCREMENT COMMENT 'restriction id ';
@@ -285,14 +344,26 @@ ALTER TABLE `post`
 -- AUTO_INCREMENT for table `users`
 --
 ALTER TABLE `users`
   MODIFY `id` int(20) NOT NULL AUTO_INCREMENT COMMENT 'id', AUTO_INCREMENT=1002;
 
+--
+-- AUTO_INCREMENT for table `usersalt`
+--
+ALTER TABLE `usersalt`
+  MODIFY `sid` int(11) NOT NULL AUTO_INCREMENT COMMENT 'salt id', AUTO_INCREMENT=2;
+
 --
 -- Constraints for dumped tables
 --
 
+--
+-- Constraints for table `adminsalt`
+--
+ALTER TABLE `adminsalt`
+  ADD CONSTRAINT `adminsalt_ibfk_1` FOREIGN KEY (`aid`) REFERENCES `admin` (`admin_id`) ON DELETE CASCADE ON UPDATE CASCADE;
+
 --
 -- Constraints for table `blocking`
 --
 ALTER TABLE `blocking`
   ADD CONSTRAINT `blocked` FOREIGN KEY (`blocked`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
@@ -335,10 +406,16 @@ ALTER TABLE `note`
 --
 -- Constraints for table `post`
 --
 ALTER TABLE `post`
   ADD CONSTRAINT `poster_id_fk` FOREIGN KEY (`poster`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
+
+--
+-- Constraints for table `usersalt`
+--
+ALTER TABLE `usersalt`
+  ADD CONSTRAINT `usersalt_ibfk_1` FOREIGN KEY (`uid`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;
 COMMIT;
 
 /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
 /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
 /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;

Vulnerable code: (1000, 'admin1@pipago.com', 'admin1login');
(1001, 'firaol', 'wakuma', '2022-04-21', 'addis abeba ', 'firaol@email.com', 'password123', 'male', 'is', '2022-04-25 14:47:39', '2022-04-25 14:47:39', '');
Fixed code: -- use password123 for both normal and admin user 
-- Generation Time: Aug 15, 2023 at 03:01 PM
(1000, 'admin@pipago.com', '86dd76e74017a9a4856c5c6d6937e471fa6f80f41b720428c0a73610d7dbbe75');

-- --------------------------------------------------------

--
-- Table structure for table `adminsalt`
--

CREATE TABLE `adminsalt` (
  `sid` int(11) NOT NULL COMMENT 'salt id',
  `aid` int(11) NOT NULL COMMENT 'admin id',
  `salt` varchar(32) NOT NULL COMMENT 'salt'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--
-- Dumping data for table `adminsalt`
--

INSERT INTO `adminsalt` (`sid`, `aid`, `salt`) VALUES
(1, 1000, '65c53cd5c62fec1766ad6bef6aac1253');
(1001, 'firaol', 'wakuma', '2022-04-21', 'addis abeba ', 'firaol@email.com', '49620aa0869973f5584dbdefc5c50b23646cab16e3f16a5cbe27cfd1a81d55d7', 'male', 'is', '2023-08-15 11:40:15', '2022-04-25 14:47:39', '');

-- --------------------------------------------------------

--
-- Table structure for table `usersalt`
--

CREATE TABLE `usersalt` (
  `sid` int(11) NOT NULL COMMENT 'salt id',
  `uid` int(11) NOT NULL COMMENT 'user id',
  `salt` varchar(32) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

--
-- Dumping data for table `usersalt`
--

INSERT INTO `usersalt` (`sid`, `uid`, `salt`) VALUES
(1, 1001, '00e7a17d32f03da112294fbed42f3c4c');
--
-- Indexes for table `adminsalt`
--
ALTER TABLE `adminsalt`
  ADD PRIMARY KEY (`sid`),
  ADD KEY `aid` (`aid`);

--
-- Indexes for table `usersalt`
--
ALTER TABLE `usersalt`
  ADD PRIMARY KEY (`sid`),
  ADD KEY `uid` (`uid`);

--
-- AUTO_INCREMENT for table `adminsalt`
--
ALTER TABLE `adminsalt`
  MODIFY `sid` int(11) NOT NULL AUTO_INCREMENT COMMENT 'salt id', AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT for table `usersalt`
--
ALTER TABLE `usersalt`
  MODIFY `sid` int(11) NOT NULL AUTO_INCREMENT COMMENT 'salt id', AUTO_INCREMENT=2;

--
-- Constraints for table `adminsalt`
--
ALTER TABLE `adminsalt`
  ADD CONSTRAINT `adminsalt_ibfk_1` FOREIGN KEY (`aid`) REFERENCES `admin` (`admin_id`) ON DELETE CASCADE ON UPDATE CASCADE;


--
-- Constraints for table `usersalt`
--
ALTER TABLE `usersalt`
  ADD CONSTRAINT `usersalt_ibfk_1` FOREIGN KEY (`uid`) REFERENCES `users` (`id`) ON DELETE CASCADE ON UPDATE CASCADE;