Nature has essentially built a concept of good and bad into us through evolution. Traits such as cooperation, reciprocity, and concern for others can improve survival and social cohesion, giving individuals who possess those traits an evolutionary advantage over those who are consistently uncooperative or harmful.
You do not necessarily need religion or philosophy to understand the basic distinction between what is good and what is harmful. Human beings already possess psychological mechanisms such as sympathy and empathy that allow us to recognize and understand the experiences of others through our own subjective experiences.
If you understand that something causes you pain, suffering, or fear, empathy allows you to recognize that the same experience is likely to be harmful to someone else. Likewise, if you understand that something brings you pleasure, security, or happiness, you can recognize that similar experiences may be beneficial to others.
That does not mean every individual instinct or emotional response is morally correct. It means that the foundations for morality can exist naturally within the human psyche, without requiring religion or a formal philosophical system to create them.